Merge lp:~jameinel/juju-ci-tools/common-main into lp:juju-ci-tools
Status: | Rejected |
---|---|
Rejected by: | Aaron Bentley |
Proposed branch: | lp:~jameinel/juju-ci-tools/common-main |
Merge into: | lp:juju-ci-tools |
Diff against target: |
125 lines (+97/-0) 2 files modified
jujupy.py (+59/-0) test_jujupy.py (+38/-0) |
To merge this branch: | bzr merge lp:~jameinel/juju-ci-tools/common-main |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Aaron Bentley | Pending | ||
Review via email: mp+262306@code.launchpad.net |
Description of the change
This is a request-
Specifically, I started to write a new assess_* module and realized that I was copy & pasting a lot of boilerplate code around parsing arguments and setting up the environment and saving logs if there are any problems.
So I wanted to factor this out into a common helper that can just get reused.
I wanted to check if people are in favor of this before I went too far on it.
One big potential concern is that I'm more comfortable adding 'named' arguments rather than positional arguments, but some of them are going to still be required (environment name, log directory, etc).
I can put them as positional arguments, but then we'd want to figure out how to do that in a common fashion. (Is juju_path always the first position on the command line, or is it always the first position after the command's custom args, etc.)
I went with passing in an ArgumentParser rather than just a custom args func because I would then also need to start passing in all the other help text that you want to have unique to the script (the __init__ to ArgumentParser takes a lot of that stuff).
I don't think this is ready to land as is, because nothing is using it. The actual 'standard_main' function isn't directly tested, because it triggers make_client and bootstrap, etc. But I noticed the main() functions of other scripts weren't tested either, and at least this way there would be 1 untested code path, instead of 10 of them.
Unmerged revisions
- 991. By John A Meinel
-
Start working on a common 'main' implementation.
I was about to copy and paste main and parse_args for yet another assess function.
It seemed useful to have a common implementation so we don't have to touch them all the time.
Hi John. Been ages since I reviewed your code!
I'm not comfortable with mandatory "optional" arguments like --environment. It's clearer if mandatory arguments are positional. The argparse docs note: Required options are generally considered bad form because users expect options to be optional, and thus they should be avoided when possible.
See also inline comments.