History

python/lib/aubio/cmd.py: add help subcommand

Paul Brossier committed 9 years ago

Commit 8a3acad1 parent 70762c51 file · +13 −2Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/lib/aubio/cmd.py+13−2
@@ -22,6 +22,8 @@ def aubio_parser(): · 21 unmodified lines
2222 subparsers = parser.add_subparsers(title='commands', dest='command',
2323 metavar="")
2424
25+ parser_add_subcommand_help(subparsers)
26+
2527 parser_add_subcommand_onset(subparsers)
2628 parser_add_subcommand_pitch(subparsers)
2729 parser_add_subcommand_beat(subparsers)
@@ -33,6 +35,12 @@ def aubio_parser(): · 5 unmodified lines
3335
3436 return parser
3537
38+def parser_add_subcommand_help(subparsers):
39+ # global help subcommand
40+ subparsers.add_parser('help',
41+ help='show help message',
42+ formatter_class = argparse.ArgumentDefaultsHelpFormatter)
43+
3644 def parser_add_subcommand_onset(subparsers):
3745 # onset subcommand
3846 subparser = subparsers.add_parser('onset',
@@ -436,10 +444,13 @@ def main(): · 397 unmodified lines
436444 sys.exit(0)
437445 elif 'verbose' in args and args.verbose > 3:
438446 sys.stderr.write('aubio version ' + aubio.version + '\n')
439− if 'command' not in args or args.command is None:
447+ if 'command' not in args or args.command is None or args.command in ['help']:
440448 # no command given, print help and return 1
441449 parser.print_help()
442− sys.exit(1)
450+ if args.command and args.command in ['help']:
451+ sys.exit(0)
452+ else:
453+ sys.exit(1)
443454 elif not args.source_uri and not args.source_uri2:
444455 sys.stderr.write("Error: a source is required\n")
445456 parser.print_help()

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t