Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an argument group for required parsed args #299

Merged
merged 2 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions gridpath/common_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ def get_scenario_name_parser():
"""

parser = ArgumentParser(add_help=False)
parser.add_argument("--scenario", required=True, type=str,
help="Name of the scenario problem to solve.")
required = parser.add_argument_group('required arguments')
required.add_argument("--scenario", required=True, type=str,
help="Name of the scenario problem to solve.")

return parser

Expand Down Expand Up @@ -145,7 +146,7 @@ def get_solve_parser():
"for which you are providing an executable.")
parser.add_argument("--mute_solver_output", default=False,
action="store_true",
help="Don't print solver output if set to true.")
help="Don't print solver output.")
parser.add_argument("--write_solver_files_to_logs_dir", default=False,
action="store_true", help="Write the temporary "
"solver files to the logs "
Expand Down
6 changes: 6 additions & 0 deletions gridpath/run_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,12 @@ def parse_arguments(args):
get_solve_parser()]
)

# Flip order of argument groups so "required arguments" show first
# https://stackoverflow.com/questions/39047075/reorder-python-argparse-argument-groups
# Note: hacky fix; preferred answer of creating an explicit optional group
# doesn't work because we combine parsers here with the parents keyword
parser._action_groups.reverse()

# Parse arguments
# TODO: should we throw warning for unknown arguments (here and in the
# other scripts)? run_start_to_end does pass unknown arguments (e.g.
Expand Down