-
Notifications
You must be signed in to change notification settings - Fork 23.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore ansible --version output #55728
Conversation
version_lines = version_string.splitlines() | ||
|
||
assert len(version_lines) == 6, 'Incorrect number of lines in "ansible --version" output' | ||
assert re.match(b'ansible [0-9.a-z]+$', version_lines[0]), 'Incorrect ansible version line in "ansible --version" output' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 this should cover it, thanks!
I think this is what you need: https://docs.python.org/2/library/argparse.html#prog prog should be set to: |
I pulled this branch and got:
Looks good! |
- Fix capsys error on Python 2.6 - Patch sys.argv in order to get the correct value in version output
Update unit tests
Add sanity test on CLI constructor to ensure args is defined. Make prog a required parameter of create_base_parser() and update all uses to pass in the newly required paramater. Update unit tests to reflect and test these changes.
* Add custom action class for version info * Use args from CLI as prog for ArgumentParser object * Make prog a required parameter of create_base_parser() and update all uses to pass in the newly required parameter. * Add unit test for checking ansible --version * Update other related unit tests
SUMMARY
Fixes #55710
The default formatting class used by
argparse
strips newline characters, resulting in the output ofansible --version
being a single string.Implement a custom action to print out the already formatted version string and add tests to prevent future regressions.
ISSUE TYPE
COMPONENT NAME
/lib/ansible/cli/arguments/option_helpers.py
ADDITIONAL INFORMATION
This only affects 2.9.