NRLMMD-GEOIPS / geoips

Main Geolocated Information Processing System code base with basic functionality enabled.
https://nrlmmd-geoips.github.io/geoips/
Other
13 stars 10 forks source link

Using ``parser.parse_known_args`` in the CLI to apply scope to arguments #637

Open evrose54 opened 2 weeks ago

evrose54 commented 2 weeks ago

Requested Update

Description

There are a couple of instances in the GeoIPS CLI where we'd like to apply some scope to arguments available to a certain command but is currently not implemented, or if it is, it's done in a hacky way. For example, we'd like to share arguments amongst all commands for --log-level, and possibly some other arguments that would apply to any command. There are also instances where we'd like to share common arguments amongst a group of commands. Currently, we share arguments amongst list commands via a GeoipsListCommon class. We add arguments to this class, and when initializing all list commands such as GeoipsListPackages, GeoipsListPlugins, etc. we add GeoipsListCommon as it's parent so they all inherit those shared arguments.

This likely could be made simpler by making use of argparse.ArgumentParser.parse_known_args command. This will allow parsing arguments that are known at the time of execution rather than at the end of initialization. By using this in a clever way, we can add global arguments to all commands and shared arguments by the group of commands. This way we can more easily control the scope of a command argument.

Background and Motivation

This issue stems from these two comments (1 : 2) on PR #465.

Code to demonstrate issue

Checklist for Completion