-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
An improvement to the use experience would be to add both separate cli script under a single parser. I have done such a think in my own project as well and it's very easy to implement by using pythons ArgumentParser class and its ability to create sub parser objects:
import argparse
main_parser = argparse.ArgumentParser(prog="olga", description="")
# Add some options to the main parser here.
# Like options that can be used for all underlying programs (like model type or
# separator).
subparsers = main_parser.add_subparsers(help="", dest="subparser_name")
# Add a sub parser to the main parser here.
# Example:
subparsers.add_parser("GenerateSeqs", help="", description="")
# Add some options to the 'GenerateSeqs' sub parser here.
# Options only used for this specific parser.
# Parse the command line arguments. The sub parser name specifies which option
# to execute.
parsed_arguments = main_parser.parse_args()
if parsed_arguments.subparser_name == "GenerateSeqs":
# Generate some sequences
# Note that the 'parsed_arguments' object only contains option arguments based
# on the given 'subparser_name' destination. This removes a lot of clutter.Hope this helps!
Cheers, Wout
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels