[PATCH tomcli 1/2] tomcli-set: fix typo in error message
Export this patch
---
src/tomcli/cli/set.py | 2 + -
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/tomcli/cli/set.py b/src/tomcli/cli/set.py
index e0c4ac8..3401f3e 100644
--- a/src/tomcli/cli/set.py
+++ b/src/tomcli/cli/set.py
@@ -153,7 +153,7 @@ def float_(ctx: Context, selector: str = Argument(...), value: float = Argument(
Set a float value in a TOML file
"""
fun_msg = (
- "I'll be very sad if you replace the whole TOML file with a string."
+ "I'll be very sad if you replace the whole TOML file with a float."
" Computers have feelings too, ya know."
)
modder: ModderCtx = ctx.ensure_object(ModderCtx)
--
2.40.1
Applied.
--
Maxwell G (@gotmax23)
Pronouns: He/They
[PATCH tomcli 2/2] tomcli-set: fix recursive dictionary creation
Export this patch
When trying to set table.section.abc, table and table.section
dictionaries should be created.
---
src/tomcli/cli/set.py | 3 + --
tests/test_tomcli_set.py | 16 ++++++++++++++++
2 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/src/tomcli/cli/set.py b/src/tomcli/cli/set.py
index 3401f3e..6dd30bc 100644
--- a/src/tomcli/cli/set.py
+++ b/src/tomcli/cli/set.py
@@ -277,8 +277,7 @@ def set_type(
break
if part not in cur and default is not ...:
cur[part] = default()
- else:
- cur = cur[part]
+ cur = cur[part]
if value is ...:
callback(cur, part) # type: ignore[call-arg]
else:
diff --git a/tests/test_tomcli_set.py b/tests/test_tomcli_set.py
index 7326cda..df72595 100644
--- a/tests/test_tomcli_set.py
+++ b/tests/test_tomcli_set.py
@@ -73,3 +73,19 @@ def test_set(rwargs, typ: str, expected):
print(ran.stdout)
assert ran.exit_code == 0
assert loads(ran.stdout) == data
+
+
+ def test_set_multilevel(reader: str, writer: str, tmp_path: Path):
+ path = tmp_path / "pyproject.toml"
+ copy2(TEST_DATA / "pyproject.toml", path)
+ with open(path, "rb") as fp:
+ data = load(fp)
+ # Replace project.license string with dict
+ data["project"]["license"] = {"text": "MIT"}
+
+ for cmd in (("del", "project.license"), ("str", "project.license.text", "MIT")):
+ args = ["--reader", reader, "--writer", writer, str(path), *cmd]
+ ran = CliRunner().invoke(app, args, catch_exceptions=False)
+ assert ran.exit_code == 0
+ with open(path, "rb") as fp:
+ assert data == load(fp)
--
2.40.1
tomcli/patches: SUCCESS in 5m30s
[tomcli-set: fix typo in error message][0] from [Maxwell G][1]
[0]: https://lists.sr.ht/~gotmax23/tomcli/patches/41073
[1]: mailto:maxwell@gtmx.me
✓ #988545 SUCCESS tomcli/patches/nox-lint.yml https://builds.sr.ht/~gotmax23/job/988545
✓ #988548 SUCCESS tomcli/patches/nox.yml https://builds.sr.ht/~gotmax23/job/988548
✓ #988547 SUCCESS tomcli/patches/nox-mockbuild.yml https://builds.sr.ht/~gotmax23/job/988547
✓ #988546 SUCCESS tomcli/patches/nox-mockbuild-36.yml https://builds.sr.ht/~gotmax23/job/988546