Skip to content

Commit c863be2

Browse files
authored
expose prog name used for argparse parser (#293)
1 parent 417688b commit c863be2

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

colcon_core/command.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,8 @@ def _parse_optional(self, arg_string):
206206
return result
207207

208208
# top level parser
209-
prog = sys.argv[0]
210-
if os.path.basename(prog) == '__main__.py':
211-
# use the module name in case the script was invoked with python -m ...
212-
prog = os.path.basename(os.path.dirname(prog))
213209
parser = CustomArgumentParser(
214-
prog=prog,
210+
prog=get_prog_name(),
215211
formatter_class=CustomFormatter,
216212
epilog=get_environment_variables_epilog(
217213
environment_variables_group_name))
@@ -224,6 +220,15 @@ def _parse_optional(self, arg_string):
224220
return parser
225221

226222

223+
def get_prog_name():
224+
"""Get the prog name used for the argparse parser."""
225+
prog = sys.argv[0]
226+
if os.path.basename(prog) == '__main__.py':
227+
# use the module name in case the script was invoked with python -m ...
228+
prog = os.path.basename(os.path.dirname(prog))
229+
return prog
230+
231+
227232
class CustomFormatter(argparse.RawDescriptionHelpFormatter):
228233
"""A custom formatter to maintain newlines."""
229234

0 commit comments

Comments
 (0)