Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/deltacode/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
7 changes: 7 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down