Skip to content

Commit

Permalink
Restructure CLI command
Browse files Browse the repository at this point in the history
Only provide `inventory lint`. We can introduce flags to control which
linters are enabled once we have more than one.
  • Loading branch information
simu committed Jan 20, 2022
1 parent 60433c4 commit efc67a4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
33 changes: 15 additions & 18 deletions commodore/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,35 +419,32 @@ def component_versions(
click.echo(yaml.safe_dump(components))


@inventory.group(
name="lint", short_help="Commands which lint the Commodore inventory structure"
)
@verbosity
@pass_config
def inventory_lint(config: Config, verbose):
config.update_verbosity(verbose)


@inventory_lint.command(
name="components",
short_help="Lint component specifications in the provided paths (files and directories are accepted)",
@inventory.command(
name="lint",
short_help="Lint YAML files for Commodore inventory structures in the provided paths",
no_args_is_help=True,
)
@click.argument(
"target", type=click.Path(file_okay=True, dir_okay=True, exists=True), nargs=-1
)
@verbosity
@pass_config
def inventory_lint_components(
config: Config,
verbose,
target: Tuple[str],
):
def inventory_lint(config: Config, verbose: int, target: Tuple[str], components: bool):
"""Lint YAML files in the provided paths.
The command assumes that any YAML file found in the provided paths is part of a
Commodore inventory structure."""
config.update_verbosity(verbose)

if len(target) == 0:
click.secho("> No files provided, exiting...", fg="yellow")
sys.exit(2)

error_counts = []
for t in target:
lint_target = Path(t)
error_counts.append(lint_components(config, lint_target))
if components:
error_counts.append(lint_components(config, lint_target))

errors = sum(error_counts)
exit_status = 0 if errors == 0 else 1
Expand Down
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/reference/cli.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,6 @@ This command doesn't have any command line options.
*-o, --output-format*::
The output format for the command. Supported values are `json` and `yaml`. Defaults to `yaml`.

== Inventory Lint Components
== Inventory Lint

No command line flags
9 changes: 6 additions & 3 deletions docs/modules/ROOT/pages/reference/commands.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,18 @@ This must match the tenant ID associated with the provided tenant repo for accur

The command supports both YAML and JSON output.

== Inventory Lint Components
== Inventory Lint

commodore inventory lint components [PATH, [PATH, [PATH, ...]]]
commodore inventory lint [PATH]...

This command provides basic linting for Commodore component specifications.
This command provides linting for Commodore inventory classes.

Currently, the command only lints component specifications.
It treats component specifications without explicit `version` field as errors.

The command takes zero or more paths to files or directories to lint as command line arguments.
It silently skips files which aren't valid YAML, as well as empty files and files containing multi-document YAML streams.
All other files are assumed to be Commodore inventory classes.

When linting directories, any hidden files (prefixed with a dot) are ignored.
Directories are linted recursively and the same skipping logic as for individual files is applied.
Expand Down

0 comments on commit efc67a4

Please sign in to comment.