Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better ux when missing validate #469

Merged
merged 1 commit into from
Nov 21, 2023
Merged
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
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
Loading