Skip to content

Commit 846894e

Browse files
authored
Add --feat and --dep flags to the inv command (#43)
1 parent 98389c1 commit 846894e

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88

99
## Unreleased
1010

11+
***Added:***
12+
13+
- Add `--feat` and `--dep` flags to the `inv` command to install extra features and dependencies
14+
1115
## 0.5.2 - 2025-03-06
1216

1317
***Fixed:***

src/dda/cli/inv/__init__.py

+46-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import click
99

10-
from dda.cli.base import dynamic_command, ensure_features_installed
10+
from dda.cli.base import dynamic_command, ensure_deps_installed, ensure_features_installed
1111
from dda.config.constants import AppEnvVars
1212

1313
if TYPE_CHECKING:
@@ -19,20 +19,59 @@
1919
context_settings={"help_option_names": [], "ignore_unknown_options": True},
2020
)
2121
@click.argument("args", nargs=-1)
22+
@click.option(
23+
"--feat",
24+
"extra_features",
25+
multiple=True,
26+
help="""\
27+
Extra features to install (multiple allowed).
28+
After a feature is installed once, it will always be available.
29+
""",
30+
)
31+
@click.option(
32+
"--dep",
33+
"extra_dependencies",
34+
multiple=True,
35+
help="""\
36+
Extra dependencies to install (multiple allowed).
37+
After a dependency is installed once, it will always be available.
38+
""",
39+
)
2240
@click.option(
2341
"--no-dynamic-deps",
2442
envvar=AppEnvVars.NO_DYNAMIC_DEPS,
2543
is_flag=True,
2644
help="Assume required dependencies are already installed",
2745
)
28-
@click.pass_obj
29-
def cmd(app: Application, *, args: tuple[str, ...], no_dynamic_deps: bool) -> None:
46+
@click.option(
47+
"-h",
48+
"--help",
49+
"show_help",
50+
is_flag=True,
51+
help="Show this help message and exit",
52+
)
53+
@click.pass_context
54+
def cmd(
55+
ctx: click.Context,
56+
*,
57+
args: tuple[str, ...],
58+
extra_features: tuple[str, ...],
59+
extra_dependencies: tuple[str, ...],
60+
no_dynamic_deps: bool,
61+
show_help: bool,
62+
) -> None:
3063
"""
3164
Invoke a local task.
3265
"""
3366
from dda.utils.fs import Path
3467

35-
features = ["legacy-tasks"]
68+
app: Application = ctx.obj
69+
70+
if show_help:
71+
app.display(ctx.get_help())
72+
return
73+
74+
features = ["legacy-tasks", *extra_features]
3675
invoke_args = [arg for arg in args if not arg.startswith("-")]
3776
if invoke_args:
3877
task = invoke_args[0]
@@ -53,4 +92,7 @@ def cmd(app: Application, *, args: tuple[str, ...], no_dynamic_deps: bool) -> No
5392
app=app,
5493
prefix=str(venv.path),
5594
)
95+
if extra_dependencies:
96+
ensure_deps_installed(list(extra_dependencies), app=app, sys_path=venv.get_sys_path(app))
97+
5698
app.subprocess.replace_current_process(["python", "-m", "invoke", *args])

0 commit comments

Comments
 (0)