gnprice / toml-cli

MIT License
120 stars 24 forks source link

Add --raw / -r option #8

Closed kurtbuilds closed 1 year ago

kurtbuilds commented 2 years ago

Some example usage based on this toml file:

[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"

[project]
name = "lumache"
authors = [{name = "Graziella", email = "graziella@lumache"}]
dynamic = ["version", "description"]
version = "0.1.0"
 $ toml get pyproject.toml project.version -r
0.1.0
$ toml get pyproject.toml project.version
"0.1.0"
$ toml get pyproject.toml project.version -r
0.1.0
$ toml get pyproject.toml project.name
"lumache"
$ toml get pyproject.toml project.name -r
lumache
$ toml get pyproject.toml project.dynamic
["version","description"]
$ toml get pyproject.toml project.dynamic -r
["version","description"]
gnprice commented 1 year ago

Thanks for sending this!

For cross-reference: the second commit here is about making toml set able to actually edit the file in place, #7. See discussion there about what the interface should be: https://github.com/gnprice/toml-cli/issues/7#issuecomment-1336105312

gnprice commented 1 year ago

I've just pushed an implementation of --raw/-r, as 3f91f138c. I found I wanted to implement it a bit differently from this version -- in particular, to match on the toml_edit::Item to see if it's a string, rather than serialize to JSON first and then match on the serde_json::Value to see if that's a string -- and I also added docs for it in the --help and the README.

I also noticed a useful cleanup in the second commit: making read_parse take a reference, which is a good improvement to the code independently of the other changes there which make it necessary. So I broke that out as its own commit 04e0a6daa and pushed that.

Let's leave the rest of the --in-place implementation for a separate PR, after discussing the question at https://github.com/gnprice/toml-cli/issues/7#issuecomment-1336105312 of whether it should instead become the default behavior.

Thanks again for this contribution! In addition to that cleanup in 04e0a6daa, this PR was useful feedback for me that --raw was a feature people do concretely want, so it was a helpful prompt for me to go and implement it :slightly_smiling_face: