Created
March 22, 2023 17:24
-
-
Save abadger/d74ac5461776974c83f298a9a2f92601 to your computer and use it in GitHub Desktop.
pseudo-python code to add a default subcommand
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--#!/usr/bin/python -tt # W: Missing module docstring | |
import argparse | |
import sys | |
global_options = argparse.ArgumentParser() | |
global_options.add_argument('--debug', action='store_true') | |
global_option_names = frozenset(('--debug', '-d', 'convert', 'analyze')) | |
common_options = argparse.ArgumentParser() | |
common_options.add_argument('--servurl') | |
>>parser = argparse.ArgumentParser(parent=[global_options]) # E: Unexpected keyword argument 'parent' in constructor call | |
sub = parser.add_subparsers(required=True) | |
>>analyze_options = sub.add_parser('analyze', parent=[global_options, common_options]) # E: line too long (84 > 79 characters) | |
>>convert_options = sub.add_parser('convert', parent=[global_options, common_options]) # E: line too long (84 > 79 characters) | |
args = sys.argv[:] | |
for index, arg in enumerate(args): | |
if arg not in global_option_names: | |
break | |
if not ('convert' in args[:index] or 'analyze' in args[:index]): | |
args.insert(0, 'convert') | |
parser.parse_args(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment