Skip to content

Commit

Permalink
refactor(chartpress): improve argument handling in main function
Browse files Browse the repository at this point in the history
- Rename remove_config_arg to _remove_config_arg to indicate private usage
- Modify _remove_config_arg to return the modified argument list
  • Loading branch information
adamblake committed Apr 20, 2024
1 parent 243010f commit 7f3fa31
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions chartpress.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ def main(argv=None):
# this could probably be clearer by using subparsers
argv = list(argv or sys.argv[1:])
argv.remove("--reset")
remove_config_arg(argv)
argv = _remove_config_arg(argv)
if len(argv) > 1:
extra_args = " ".join(shlex.quote(arg) for arg in argv)
argparser.error(
Expand Down Expand Up @@ -1324,7 +1324,9 @@ def main(argv=None):
)


def remove_config_arg(argv):
def _remove_config_arg(argv):
argv = [*argv]

# get the index for --config, --config=something, or None
config_idx = next(
(i for i, arg in enumerate(argv) if arg.startswith("--config")),
Expand All @@ -1337,6 +1339,8 @@ def remove_config_arg(argv):
# remove the value of the --config argument if it was passed separately
argv.pop(config_idx)

return argv


if __name__ == "__main__":
main()

0 comments on commit 7f3fa31

Please sign in to comment.