Skip to content

Commit 1603895

Browse files
committed
Fix dynamic flag binding and bump version to 0.0.5
1 parent cb3d93d commit 1603895

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

envlit/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,14 @@ def parse_args(self, ctx: click.Context, args: list):
120120

121121
# Get flag aliases
122122
flag_aliases = flag_config.get("flag", [f"--{flag_name}"])
123+
if isinstance(flag_aliases, str):
124+
flag_aliases = [flag_aliases]
123125
default_value = flag_config.get("default", None)
124126
target = flag_config.get("target", flag_name.upper())
125127

126128
# Add option to command
127129
option = click.Option(
128-
param_decls=flag_aliases,
130+
param_decls=[*flag_aliases, flag_name],
129131
default=default_value,
130132
help=f"Set {target} (default: {default_value})",
131133
)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "envlit"
3-
version = "0.0.4"
3+
version = "0.0.5"
44
description = "A minimal CLI tool to organize, load, and switch between your project's environment contexts."
55
authors = [{ name = "Chaofan Luo" }]
66
readme = "README.md"

tests/test_cli_init.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,42 @@ def test_init_includes_error_handling(runner):
166166
assert "if envlit unload" in output
167167
assert "else" in output
168168
assert "Error: Failed to generate" in output
169+
170+
171+
def test_load_binds_dynamic_flag_value_to_config_key(runner, tmp_path):
172+
"""Test dynamic flags still work when config key differs from long option name."""
173+
config_file = tmp_path / "devices.yaml"
174+
config_file.write_text("""
175+
flags:
176+
num_devices:
177+
flag: ["--num"]
178+
default: "8"
179+
target: "FSDP_DEVICES"
180+
hooks:
181+
post_load:
182+
- name: "Show devices"
183+
script: "echo $FSDP_DEVICES"
184+
""")
185+
186+
result = runner.invoke(cli, ["load", "--config", str(config_file), "--num", "4"])
187+
188+
assert result.exit_code == 0
189+
assert 'export FSDP_DEVICES="4"' in result.output
190+
assert "echo $FSDP_DEVICES" in result.output
191+
192+
193+
def test_load_preserves_existing_dynamic_flag_behavior(runner, tmp_path):
194+
"""Test dynamic flags continue to work when config key matches option name."""
195+
config_file = tmp_path / "cuda.yaml"
196+
config_file.write_text("""
197+
flags:
198+
cuda:
199+
flag: ["--cuda", "-g"]
200+
default: "0"
201+
target: "CUDA_VISIBLE_DEVICES"
202+
""")
203+
204+
result = runner.invoke(cli, ["load", "--config", str(config_file), "-g", "0,1"])
205+
206+
assert result.exit_code == 0
207+
assert 'export CUDA_VISIBLE_DEVICES="0,1"' in result.output

0 commit comments

Comments
 (0)