From 5673ba6e0f0bb139449cbe19b85c31a2aa37ebdd Mon Sep 17 00:00:00 2001 From: "John M. Horan" Date: Tue, 3 Apr 2018 18:37:16 -0700 Subject: [PATCH] Add --version command #80 Signed-off-by: John M. Horan --- src/deltacode/cli.py | 8 ++++++++ tests/test_cli.py | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/src/deltacode/cli.py b/src/deltacode/cli.py index 54516e23..8ac0cb8d 100644 --- a/src/deltacode/cli.py +++ b/src/deltacode/cli.py @@ -55,8 +55,16 @@ def write_json(deltacode, outfile, all_delta_types=False): outfile.write('\n') +def print_version(ctx, param, value): + if not value or ctx.resilient_parsing: + return + click.echo('DeltaCode version ' + __version__) + ctx.exit() + + @click.command() @click.help_option('-h', '--help') +@click.option('--version', is_flag=True, is_eager=True, expose_value=False, callback=print_version, help='Show the version and exit.') @click.option('-n', '--new', required=True, prompt=False, type=click.Path(exists=True, readable=True), help='Identify the path to the "new" scan file') @click.option('-o', '--old', required=True, prompt=False, type=click.Path(exists=True, readable=True), help='Identify the path to the "old" scan file') @click.option('-j', '--json-file', prompt=False, default='-', type=click.File(mode='wb', lazy=False), help='Identify the path to the .json output file') diff --git a/tests/test_cli.py b/tests/test_cli.py index f9865a27..1d506d5e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -422,6 +422,13 @@ def test_help(self): assert 'Identify the changes that need to be made' in result.output assert 'If no file option is selected' in result.output assert 'Include unmodified files' in result.output + assert '--version' in result.output + + def test_version(self): + runner = CliRunner() + result = runner.invoke(cli.cli, ['--version']) + + assert 'DeltaCode version' in result.output def test_empty(self): runner = CliRunner()