Skip to content

Commit

Permalink
ansible-galaxy tidy up arg parse with better validation (#59957)
Browse files Browse the repository at this point in the history
* ansible-galaxy tidy up arg parse with better validation

* Add support back in for -v before sub aprser

* Added deprecation warning for manually parsed verbosity
  • Loading branch information
jborean93 committed Aug 13, 2019
1 parent 1b8aa79 commit 14a7722
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 161 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/galaxy-argspec-verbosity.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
deprecated_features:
- Deprecated setting the verbosity before the sub command for ``ansible-galaxy`` and ``ansible-vault``. Set the verbosity level after the sub command, e.g. do ``ansible-galaxy init -v`` and not ``ansible-galaxy -v init``.
10 changes: 10 additions & 0 deletions lib/ansible/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,16 @@ def post_process_args(self, options):
else:
options.inventory = C.DEFAULT_HOST_LIST

# Dup args set on the root parser and sub parsers results in the root parser ignoring the args. e.g. doing
# 'ansible-galaxy -vvv init' has no verbosity set but 'ansible-galaxy init -vvv' sets a level of 3. To preserve
# back compat with pre-argparse changes we manually scan and set verbosity based on the argv values.
if self.parser.prog in ['ansible-galaxy', 'ansible-vault'] and not options.verbosity:
verbosity_arg = next(iter([arg for arg in self.args if arg.startswith('-v')]), None)
if verbosity_arg:
display.deprecated("Setting verbosity before the arg sub command is deprecated, set the verbosity "
"after the sub command", "2.13")
options.verbosity = verbosity_arg.count('v')

return options

def parse(self):
Expand Down

0 comments on commit 14a7722

Please sign in to comment.