Skip to content

Commit c2af0b2

Browse files
authored
Merge pull request #96 from nexB/80-add-version-command
Add --version command #80
2 parents 09b365b + 5673ba6 commit c2af0b2

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/deltacode/cli.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,16 @@ def write_json(deltacode, outfile, all_delta_types=False):
5555
outfile.write('\n')
5656

5757

58+
def print_version(ctx, param, value):
59+
if not value or ctx.resilient_parsing:
60+
return
61+
click.echo('DeltaCode version ' + __version__)
62+
ctx.exit()
63+
64+
5865
@click.command()
5966
@click.help_option('-h', '--help')
67+
@click.option('--version', is_flag=True, is_eager=True, expose_value=False, callback=print_version, help='Show the version and exit.')
6068
@click.option('-n', '--new', required=True, prompt=False, type=click.Path(exists=True, readable=True), help='Identify the path to the "new" scan file')
6169
@click.option('-o', '--old', required=True, prompt=False, type=click.Path(exists=True, readable=True), help='Identify the path to the "old" scan file')
6270
@click.option('-j', '--json-file', prompt=False, default='-', type=click.File(mode='wb', lazy=False), help='Identify the path to the .json output file')

tests/test_cli.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,13 @@ def test_help(self):
422422
assert 'Identify the changes that need to be made' in result.output
423423
assert 'If no file option is selected' in result.output
424424
assert 'Include unmodified files' in result.output
425+
assert '--version' in result.output
426+
427+
def test_version(self):
428+
runner = CliRunner()
429+
result = runner.invoke(cli.cli, ['--version'])
430+
431+
assert 'DeltaCode version' in result.output
425432

426433
def test_empty(self):
427434
runner = CliRunner()

0 commit comments

Comments
 (0)