jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/374132 )
Change subject: CLI: fix --version option ...................................................................... CLI: fix --version option Change-Id: Iadf1a08d3dd955141cb0847fd58a9f1ffcc9a175 --- M cumin/cli.py M cumin/tests/integration/test_cli.py 2 files changed, 16 insertions(+), 6 deletions(-) Approvals: jenkins-bot: Verified Volans: Looks good to me, approved diff --git a/cumin/cli.py b/cumin/cli.py index 9c236dd..755607b 100644 --- a/cumin/cli.py +++ b/cumin/cli.py @@ -110,7 +110,7 @@ '[optional]')) parser.add_argument('--dry-run', action='store_true', help='Do not execute any command, just return the list of matching hosts and exit.') - parser.add_argument('--version', action='store_true', help='Print current version and exit.') + parser.add_argument('--version', action='version', version='%(prog)s {version}'.format(version=cumin.__version__)) parser.add_argument('-d', '--debug', action='store_true', help='Set log level to DEBUG.') parser.add_argument('--trace', action='store_true', help='Set log level to TRACE, a custom logging level intended for development debugging.') @@ -353,10 +353,6 @@ # Setup try: args = parse_args(argv) - if args.version: - tqdm.write('cumin {version}'.format(version=cumin.__version__)) - return 0 - user = get_running_user() config = cumin.Config(args.config) setup_logging(config['log_file'], debug=args.debug, trace=args.trace) diff --git a/cumin/tests/integration/test_cli.py b/cumin/tests/integration/test_cli.py index d2c0e84..3ae90cd 100644 --- a/cumin/tests/integration/test_cli.py +++ b/cumin/tests/integration/test_cli.py @@ -9,7 +9,7 @@ import pytest -from cumin import cli +from cumin import __version__, cli # Set environment variables _ENV = {'USER': 'root', 'SUDO_USER': 'user'} @@ -376,3 +376,17 @@ assert _EXPECTED_LINES['all_failure'] in err, _EXPECTED_LINES['all_failure'] assert _EXPECTED_LINES['failed'] not in err, _EXPECTED_LINES['failed'] assert rc == 2 + + def test_version(self, capsys): # pylint: disable=no-self-use + """Calling --version should return the version and exit.""" + with pytest.raises(SystemExit) as e: + cli.main(argv=['--version']) + + out, err = capsys.readouterr() + sys.stdout.write(out) + sys.stderr.write(err) + assert e.type == SystemExit + assert e.value.code == 0 + assert out == '' + assert len(err.splitlines()) == 1 + assert __version__ in err -- To view, visit https://gerrit.wikimedia.org/r/374132 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Iadf1a08d3dd955141cb0847fd58a9f1ffcc9a175 Gerrit-PatchSet: 1 Gerrit-Project: operations/software/cumin Gerrit-Branch: master Gerrit-Owner: Volans <rcocci...@wikimedia.org> Gerrit-Reviewer: Faidon Liambotis <fai...@wikimedia.org> Gerrit-Reviewer: Gehel <guillaume.leder...@wikimedia.org> Gerrit-Reviewer: Giuseppe Lavagetto <glavage...@wikimedia.org> Gerrit-Reviewer: Volans <rcocci...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits