Skip to content

Commit

Permalink
feat: better ux when missing validate
Browse files Browse the repository at this point in the history
  • Loading branch information
gadomski committed Nov 17, 2023
1 parent 36ad7cb commit 7b6864a
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/stactools/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# flake8: noqa

import sys
from typing import Callable

from click import Group, Command

import stactools.core

try:
Expand Down Expand Up @@ -59,11 +64,44 @@ def register_plugin(registry: "Registry") -> None:
from stactools.cli.commands import validate

registry.register_subcommand(validate.create_validate_command)
else:
registry.register_subcommand(
_missing_optional_dependency(command="validate", dependency="validate")
)

if HAS_STAC_CHECK:
from stactools.cli.commands import lint

registry.register_subcommand(lint.create_lint_command)
else:
registry.register_subcommand(
_missing_optional_dependency(command="lint", dependency="validate")
)


def _missing_optional_dependency(
command: str, dependency: str
) -> Callable[[Group], Command]:
def f(cli: Group) -> Command:
@cli.command(
command,
short_help=f"Unsupported (needs `pip install 'stactools[{dependency}]')",
)
def inner() -> None:
print(f"Error: No such command '{command}'", file=sys.stderr)
print(
f"This command is provided by an optional dependency '{dependency}'",
file=sys.stderr,
)
print(
f"To enable, install stactools with the optional dependency: pip install 'stactools[{dependency}]'",
file=sys.stderr,
)
sys.exit(1)

return inner

return f


from stactools.cli.registry import Registry
Expand Down

0 comments on commit 7b6864a

Please sign in to comment.