Skip to content

Combining the generation and Pgen OLGA command scripts #3

@penuts7644

Description

@penuts7644

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions