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

fix: let 'set' command fail on key not found #33

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions tests/toml_cli/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ def test_set_value(tmp_path: pathlib.Path):
"""
)

result = runner.invoke(app, ["set", "--toml-path", str(test_toml_path), "person.KEY_THAT_DOES_NOT_EXIST.name", "15"])
assert result.exit_code == 1

result = runner.invoke(app, ["set", "--toml-path", str(test_toml_path), "person.age", "15"])
assert result.exit_code == 0
assert 'age = "15"' in test_toml_path.read_text()
Expand Down
3 changes: 2 additions & 1 deletion toml_cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def set_(
try:
toml_part = toml_part[key_part]
except tomlkit.exceptions.NonExistentKey:
typer.echo(f"Key {key} can not set", err=True)
typer.echo(f"error: non-existent key '{key}' can not be set to value '{value}'", err=True)
exit(1)

if to_int:
value = int(value)
Expand Down