canonical / canonical/craft-cli
Simplify the Dispatcher usage
- Dominant language
- Python
- Stars
- 16
- Forks
- 27
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 10
Description
Currently, before instantiaton, the following steps are needed:
- `pre_parse_args`: will parse all arguments and return all global args, *very* useful for the app to react on custom global arguments
- `load_command`: useful to pass the loaded app config
- `run`: finally run the command
We could have a more simple usage. Two models are described below:
**The explicit one:**
Let's provide a `simple_run` method (name to be determined) that will be the equivalent to:
```
dispatcher.pre_parse_args(sys.argv[1:]) # sys.argv usage by default, and no use of returned global args
dispatcher.load_command(None) # no app config passed
dispatcher.run()
```
**The implicit one:**
We can assume no special needs in the previous step, and run it implicitly in case it was not run explicitly before:
- if the developer called `load_command` without calling `pre_parse_args` before, just call `pre_parse_args(sys.argv[1:])`.
- if the developer called `run` without calling `load_command`, just call `load_command(None)` (which may trigger previous item too)
Contributor guide
Research direction
Start by locating the Dispatcher implementation and its pre_parse_args, load_command, and run methods. Compare the explicit simple_run proposal with the implicit behavior proposal, then confirm the intended API with maintainers. Done means the chosen approach lets callers run a command without the currently required sequence while preserving existing explicit usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100