diff --git a/tests/toml_cli/test_init.py b/tests/toml_cli/test_init.py index fb5feeb..ef27309 100644 --- a/tests/toml_cli/test_init.py +++ b/tests/toml_cli/test_init.py @@ -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() diff --git a/toml_cli/__init__.py b/toml_cli/__init__.py index aa51b14..ee286a3 100644 --- a/toml_cli/__init__.py +++ b/toml_cli/__init__.py @@ -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)