Skip to content

Commit

Permalink
Make --version output valid YAML for parsing #2856
Browse files Browse the repository at this point in the history
This commit adds a colon so the --version output goes from

ScanCode version 30.1.0
ScanCode Output Format version 2.0.0
SPDX License list version 3.15

to

ScanCode version: 30.1.0
ScanCode Output Format version: 2.0.0
SPDX License list version: 3.15

This will make the output easier to parse since it is valid YAML now.
This also includes a test validating this behavior.

Signed-off-by: Kevin Ji <kyji1011@gmail.com>
  • Loading branch information
KevinJi22 committed Feb 8, 2022
1 parent 4bd9c8e commit b78b49f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/scancode/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ def print_examples(ctx, param, value):
def print_version(ctx, param, value):
if not value or ctx.resilient_parsing:
return
click.echo('ScanCode version ' + scancode_config.__version__)
click.echo('ScanCode Output Format version ' + scancode_config.__output_format_version__)
click.echo('SPDX License list version ' + scancode_config.spdx_license_list_version)
click.echo(f'ScanCode version: {scancode_config.__version__}')
click.echo(f'ScanCode Output Format version: {scancode_config.__output_format_version__}')
click.echo(f'SPDX License list version: {scancode_config.spdx_license_list_version}')
ctx.exit()


Expand Down
11 changes: 11 additions & 0 deletions tests/scancode/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,3 +929,14 @@ def test_VirtualCodebase_output_with_from_json_is_same_as_original():

assert json.dumps(results , indent=2) == json.dumps(expected, indent=2)
assert len(results_headers) == len(expected_headers) + 1

def test_getting_version_returns_valid_yaml():
import saneyaml
import scancode_config
args = ['--version']
result = run_scan_click(args)
assert saneyaml.load(result.output) == {
'ScanCode version': f'{scancode_config.__version__}',
'ScanCode Output Format version': f'{scancode_config.__output_format_version__}',
'SPDX License list version': f'{scancode_config.spdx_license_list_version}'
}

0 comments on commit b78b49f

Please sign in to comment.