def _cli_data(parser, filenames=None, known=None): ArgumentParser = type(parser) common = ArgumentParser(add_help=False) # These flags will get processed by the top-level parse_args(). add_verbosity_cli(common) add_traceback_cli(common) subs = parser.add_subparsers(dest='datacmd') sub = subs.add_parser('show', parents=[common]) if known is None: sub.add_argument('--known', required=True) if filenames is None: sub.add_argument('filenames', metavar='FILE', nargs='+') sub = subs.add_parser('dump', parents=[common]) if known is None: sub.add_argument('--known') sub.add_argument('--show', action='store_true') process_progress = add_progress_cli(sub) sub = subs.add_parser('check', parents=[common]) if known is None: sub.add_argument('--known', required=True) def process_args(args): if args.datacmd == 'dump': process_progress(args) return process_args
def parse_args(argv=sys.argv[1:]): import argparse from c_common.scriptutil import ( add_verbosity_cli, add_traceback_cli, process_args_by_key, ) from cpython.__main__ import _cli_check parser = argparse.ArgumentParser() processors = [ add_verbosity_cli(parser), add_traceback_cli(parser), #_cli_check(parser, checks='<globals>'), _cli_check(parser), ] args = parser.parse_args() ns = vars(args) cmd = 'check' verbosity, traceback_cm = process_args_by_key( args, argv, processors, ['verbosity', 'traceback_cm'], ) return cmd, ns, verbosity, traceback_cm