From 3579fd59a8f09bd2bfe35157350843b3f85c9593 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Sat, 8 Apr 2023 23:55:14 -0700 Subject: [PATCH] make sure subcommand help prints more useful help message.. --- ui/medashare/cli.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/ui/medashare/cli.py b/ui/medashare/cli.py index 7728a17..c43e5b3 100644 --- a/ui/medashare/cli.py +++ b/ui/medashare/cli.py @@ -1421,6 +1421,9 @@ def main(): subparsers = parser.add_subparsers(title='subcommands', description='valid subcommands', help='additional help') + parser_help = subparsers.add_parser('help', help='get help') + parser_help.set_defaults(func=lambda *args: (parser.print_help(), sys.exit(0))) + parser_gi = subparsers.add_parser('genident', help='generate identity') parser_gi.add_argument('tagvalue', nargs='+', help='add the arg as metadata for the identity, tag=[value]') @@ -2259,6 +2262,31 @@ class _TestCases(unittest.TestCase): self.assertEqual(s, str(pathpref / '.medashare_store.sqlite3')) self.assertEqual(c, str(pathpref / '.medashare_cache.pasn1')) + def test_help(self): + # that subcommand help is the same as --help + + with mock.patch('sys.stdout', io.StringIO()) as stdout, \ + mock.patch('sys.argv', [ 'progname', '--help', ]) as argv: + with self.assertRaises(SystemExit) as cm: + main() + + # XXX - Minor hack till other tests fixed + sys.exit(0) + + dashhelp = stdout.getvalue() + + with mock.patch('sys.stdout', io.StringIO()) as stdout, \ + mock.patch('sys.argv', [ 'progname', 'help', ]) as argv: + with self.assertRaises(SystemExit) as cm: + main() + + # XXX - Minor hack till other tests fixed + sys.exit(0) + + subhelp = stdout.getvalue() + + self.assertEqual(dashhelp, subhelp) + #@unittest.skip('temp') def test_cmds(self): cmds = sorted(self.fixtures.glob('cmd.*.json'))