Skip to content

Instantly share code, notes, and snippets.

@mahmoud
Last active May 1, 2019 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahmoud/8f60dd54c4729a71b5c3f7d0e64fe37a to your computer and use it in GitHub Desktop.
Save mahmoud/8f60dd54c4729a71b5c3f7d0e64fe37a to your computer and use it in GitHub Desktop.
(based on years of argparse experience, also serves to demonstrate why argparse is not so good)
def create_parser():
root_parser = ArgumentParser(description='article fetch operations')
root_parser.add_argument('--list_home', help='list lookup directory')
add_subparsers(root_parser.add_subparsers())
return root_parser
def add_subparsers(subparsers):
parser_list = subparsers.add_parser('list')
parser_list.add_argument('target_list', nargs='?',
help='Name of the list or list file')
parser_list.set_defaults(func=get_list)
...
def main(argv=None):
parser = create_parser()
args = parser.parse_args(argv)
kwargs = dict(args._get_kwargs())
args.func(**kwargs)
return
if __name__ == '__main__':
sys.exit(main())
$ chert -h
usage: chert [-h] {init,version,serve,render,publish,clean} ...
positional arguments:
{init,version,serve,render,publish,clean}
chert supports init, serve, and publish subcommands
init create a new Chert site
version display the version and other metadata
serve work on a Chert site using the local server
render generate a local copy of the site
publish upload a Chert site to the remote server
clean clean Chert output site directory
optional arguments:
-h, --help show this help message and exit
$ chert -h
Usage: /home/mahmoud/virtualenvs/chert/bin/chert subcommand [FLAGS]
Subcommands:
init create a new Chert site
serve work on a Chert site using the local server
render generate a local copy of the site
publish upload a Chert site to the remote server
clean clean Chert output site directory
version display the version and other metadata
Flags:
--help / -h show this help message and exit
$ python tools/admin.py import-gist --help
Usage: tools/admin.py import_gist [FLAGS]
import round entries from a csv list
Flags:
--help / -h show this help message and exit
--debug get extra output, enable debug console before db commit
--round-id ROUND_ID integer (required)
--url URL str (required)
$ python tools/admin.py -h
Usage: tools/admin.py subcommand [FLAGS]
CLI tools for administrating Montage.
Subcommands:
add-organizer Add a top-level organizer to the system, capable of creating campaigns and adding
coordinators.
add-coordinator add specified user as coordinator of a given campaign
create-campaign interactively create a campaign
cancel-campaign cancel the specified campaign
create-round interactively create a round in the specified campaign
import-gist import round entries from a csv list
activate-round activate a round to start or resume voting
pause-round pause a round to make edits and perform other maintenance
advance-round finalize the specified round and start the next
edit-round-quorum change the quorum of a given round, assigning and reassigning tasks as need be
check-round-dupes check for double-assigned tasks or ratings in a specified round
apply-round-ratings apply ratings to a round based on an input file
retask-duplicate-ratings reassign all ratings that were duplicated
shuffle-round-assignments randomly reassign all the rating tasks in a round
cancel-round set a round as cancelled, cancel related tasks and remove it from the campaign's active
rounds.
list-campaigns list details about all campaigns
rdb-console Load a developer console for interacting with database objects.
Flags:
--help / -h show this help message and exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment