Skip to content

Commit 0c31580

Browse files
authored
[dg] verb-first env cli commands (#29115)
## Summary Move `dg env list` to `dg list env`, and `dg plus env pull` to `dg plus pull env` ## Test Plan Unit tests. ## Changelog > `[dagster-dg]` The `dg env list` command is now `dg list env` > `[dagster-dg]` The `dg plus env pull` command is now `dg plus pull env`
1 parent c70b1be commit 0c31580

File tree

9 files changed

+76
-104
lines changed

9 files changed

+76
-104
lines changed

Diff for: examples/docs_snippets/docs_snippets/guides/components/index/1-help.txt

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Usage: dg [OPTIONS] COMMAND [ARGS]...
2323
│ check Commands for checking the integrity of your Dagster code. │
2424
│ dev Start a local instance of Dagster. │
2525
│ docs Commands for generating docs from your Dagster code. │
26-
│ env Commands for managing environment variables. │
2726
│ init Initialize a new Dagster project or workspace. │
2827
│ launch Launch a Dagster run. │
2928
│ list Commands for listing Dagster entities. │

Diff for: python_modules/libraries/dagster-dg/dagster_dg/cli/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from dagster_dg.cli.check import check_group
77
from dagster_dg.cli.dev import dev_command
88
from dagster_dg.cli.docs import docs_group
9-
from dagster_dg.cli.env import env_group
109
from dagster_dg.cli.init import init_command
1110
from dagster_dg.cli.launch import launch_command
1211
from dagster_dg.cli.list import list_group
@@ -29,7 +28,6 @@ def create_dg_cli():
2928
commands={
3029
"check": check_group,
3130
"docs": docs_group,
32-
"env": env_group,
3331
"utils": utils_group,
3432
"launch": launch_command,
3533
"list": list_group,

Diff for: python_modules/libraries/dagster-dg/dagster_dg/cli/env.py

-44
This file was deleted.

Diff for: python_modules/libraries/dagster-dg/dagster_dg/cli/list.py

+28
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from dagster_dg.component import PluginObjectFeature, RemotePluginRegistry
2424
from dagster_dg.config import normalize_cli_config
2525
from dagster_dg.context import DgContext
26+
from dagster_dg.env import ProjectEnvVars
2627
from dagster_dg.utils import DgClickCommand, DgClickGroup
2728
from dagster_dg.utils.telemetry import cli_telemetry_wrapper
2829

@@ -309,3 +310,30 @@ def list_defs_command(output_json: bool, **global_options: object) -> None:
309310
table.add_row("Sensors", _get_sensors_table(sensors))
310311

311312
console.print(table)
313+
314+
315+
# ########################
316+
# ##### ENVIRONMENT
317+
# ########################
318+
319+
320+
@list_group.command(name="env", cls=DgClickCommand)
321+
@dg_global_options
322+
@cli_telemetry_wrapper
323+
def list_env_command(**global_options: object) -> None:
324+
"""List environment variables from the .env file of the current project."""
325+
cli_config = normalize_cli_config(global_options, click.get_current_context())
326+
dg_context = DgContext.for_project_environment(Path.cwd(), cli_config)
327+
328+
env = ProjectEnvVars.from_ctx(dg_context)
329+
if not env.values:
330+
click.echo("No environment variables are defined for this project.")
331+
return
332+
333+
table = Table(border_style="dim")
334+
table.add_column("Env Var")
335+
table.add_column("Value")
336+
for key, value in env.values.items():
337+
table.add_row(key, value)
338+
console = Console()
339+
console.print(table)

Diff for: python_modules/libraries/dagster-dg/dagster_dg/cli/plus.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ def login_command() -> None:
7676
# ########################
7777

7878

79-
@plus_group.group(name="env", cls=DgClickGroup)
80-
def plus_env_group():
81-
"""Commands for managing environment variables in Dagster Plus."""
79+
@plus_group.group(name="pull", cls=DgClickGroup)
80+
def plus_pull_group():
81+
"""Commands for pulling configuration from Dagster Plus."""
8282

8383

8484
def _get_local_secrets_for_locations(
@@ -99,7 +99,7 @@ def _get_local_secrets_for_locations(
9999
return secrets_by_location
100100

101101

102-
@plus_env_group.command(name="pull", cls=DgClickCommand)
102+
@plus_pull_group.command(name="env", cls=DgClickCommand)
103103
@dg_global_options
104104
@cli_telemetry_wrapper
105105
def pull_env_command(**global_options: object) -> None:
@@ -109,7 +109,7 @@ def pull_env_command(**global_options: object) -> None:
109109
dg_context = DgContext.for_workspace_or_project_environment(Path.cwd(), cli_config)
110110
if not DagsterPlusCliConfig.exists():
111111
raise click.UsageError(
112-
"`dg plus env pull` requires authentication with Dagster Plus. Run `dg plus login` to authenticate."
112+
"`dg plus pull env` requires authentication with Dagster Plus. Run `dg plus login` to authenticate."
113113
)
114114
config = DagsterPlusCliConfig.get()
115115

Diff for: python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/plus_tests/test_pull_env_command.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ def test_pull_env_command_no_auth(monkeypatch):
2424
):
2525
monkeypatch.setenv("DG_CLI_CONFIG", str(Path(cloud_config_dir) / "dg.toml"))
2626
monkeypatch.setenv("DAGSTER_CLOUD_CLI_CONFIG", str(Path(cloud_config_dir) / "config"))
27-
result = runner.invoke("plus", "env", "pull")
27+
result = runner.invoke("plus", "pull", "env")
2828
assert result.exit_code != 0, result.output + " " + str(result.exception)
2929
assert (
30-
"`dg plus env pull` requires authentication with Dagster Plus. Run `dg plus login` to authenticate."
30+
"`dg plus pull env` requires authentication with Dagster Plus. Run `dg plus login` to authenticate."
3131
in str(result.output)
3232
)
3333

@@ -50,7 +50,7 @@ def test_pull_env_command_auth_err(dg_plus_cli_config):
5050
},
5151
expected_variables={"onlyViewable": True, "scopes": {"localDeploymentScope": True}},
5252
)
53-
result = runner.invoke("plus", "env", "pull")
53+
result = runner.invoke("plus", "pull", "env")
5454
assert result.exit_code != 0, result.output + " " + str(result.exception)
5555
assert "Unauthorized: Not authorized" in str(result.output)
5656

@@ -74,7 +74,7 @@ def test_pull_env_command_python_err(dg_plus_cli_config):
7474
},
7575
expected_variables={"onlyViewable": True, "scopes": {"localDeploymentScope": True}},
7676
)
77-
result = runner.invoke("plus", "env", "pull")
77+
result = runner.invoke("plus", "pull", "env")
7878
assert result.exit_code != 0, result.output + " " + str(result.exception)
7979
assert "Error: An error has occurred" in str(result.output)
8080

@@ -121,7 +121,7 @@ def test_pull_env_command_project(dg_plus_cli_config):
121121
},
122122
expected_variables={"onlyViewable": True, "scopes": {"localDeploymentScope": True}},
123123
)
124-
result = runner.invoke("plus", "env", "pull")
124+
result = runner.invoke("plus", "pull", "env")
125125
assert result.exit_code == 0, result.output + " " + str(result.exception)
126126
assert result.output.strip() == "Environment variables saved to .env"
127127

@@ -174,7 +174,7 @@ def test_pull_env_command_workspace(dg_plus_cli_config):
174174
},
175175
expected_variables={"onlyViewable": True, "scopes": {"localDeploymentScope": True}},
176176
)
177-
result = runner.invoke("plus", "env", "pull")
177+
result = runner.invoke("plus", "pull", "env")
178178
assert result.exit_code == 0, result.output + " " + str(result.exception)
179179
assert (
180180
result.output.strip()

Diff for: python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/test_env_commands.py

-45
This file was deleted.

Diff for: python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/test_environment_validation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def to_cli_args(self) -> tuple[str, ...]:
6666
CommandSpec(("check", "yaml")),
6767
CommandSpec(("list", "component")),
6868
CommandSpec(("list", "defs")),
69+
CommandSpec(("list", "env")),
6970
CommandSpec(("scaffold", DEFAULT_COMPONENT_TYPE, "foot")),
70-
CommandSpec(("env", "list")),
7171
]
7272

7373
WORKSPACE_CONTEXT_COMMANDS = [

Diff for: python_modules/libraries/dagster-dg/dagster_dg_tests/cli_tests/test_list_commands.py

+36
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
ensure_dagster_dg_tests_import()
1111

12+
from dagster_dg.utils import ensure_dagster_dg_tests_import
13+
1214
from dagster_dg_tests.utils import (
1315
ProxyRunner,
1416
assert_runner_result,
@@ -432,3 +434,37 @@ def _sample_env_var_assets():
432434
@asset(kinds={"sling"}, group_name=os.getenv("GROUP_NAME", "MISSING"))
433435
def alpha():
434436
pass
437+
438+
439+
# ########################
440+
# ##### LIST
441+
# ########################
442+
443+
444+
def test_list_env_succeeds():
445+
with (
446+
ProxyRunner.test(use_fixed_test_components=True) as runner,
447+
isolated_example_project_foo_bar(runner, in_workspace=False),
448+
):
449+
result = runner.invoke("list", "env")
450+
assert_runner_result(result)
451+
assert (
452+
result.output.strip()
453+
== textwrap.dedent("""
454+
No environment variables are defined for this project.
455+
""").strip()
456+
)
457+
458+
Path(".env").write_text("FOO=bar")
459+
result = runner.invoke("list", "env")
460+
assert_runner_result(result)
461+
assert (
462+
result.output.strip()
463+
== textwrap.dedent("""
464+
┏━━━━━━━━━┳━━━━━━━┓
465+
┃ Env Var ┃ Value ┃
466+
┡━━━━━━━━━╇━━━━━━━┩
467+
│ FOO │ bar │
468+
└─────────┴───────┘
469+
""").strip()
470+
)

0 commit comments

Comments
 (0)