Skip to content

Commit

Permalink
expose prog name used for argparse parser (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
dirk-thomas authored Jan 14, 2020
1 parent 417688b commit c863be2
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions colcon_core/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,8 @@ def _parse_optional(self, arg_string):
return result

# top level parser
prog = sys.argv[0]
if os.path.basename(prog) == '__main__.py':
# use the module name in case the script was invoked with python -m ...
prog = os.path.basename(os.path.dirname(prog))
parser = CustomArgumentParser(
prog=prog,
prog=get_prog_name(),
formatter_class=CustomFormatter,
epilog=get_environment_variables_epilog(
environment_variables_group_name))
Expand All @@ -224,6 +220,15 @@ def _parse_optional(self, arg_string):
return parser


def get_prog_name():
"""Get the prog name used for the argparse parser."""
prog = sys.argv[0]
if os.path.basename(prog) == '__main__.py':
# use the module name in case the script was invoked with python -m ...
prog = os.path.basename(os.path.dirname(prog))
return prog


class CustomFormatter(argparse.RawDescriptionHelpFormatter):
"""A custom formatter to maintain newlines."""

Expand Down

0 comments on commit c863be2

Please sign in to comment.