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

Set int and bool values as well as strings #16

Open
liubin opened this issue Dec 3, 2022 · 3 comments
Open

Set int and bool values as well as strings #16

liubin opened this issue Dec 3, 2022 · 3 comments

Comments

@liubin
Copy link
Contributor

liubin commented Dec 3, 2022

Originally posted by @gnprice in #13 (comment):

Hmm, this [in that PR version] feels rather too magical to me for the interface of this command. In particular, this means that even when you're just trying to write string data, you'll sometimes have it come out as an int or a bool instead, just depending on the data -- depending on exactly what string it was you were trying to store.

Or for another angle on the same thing: this approach would mean that it'd be impossible to store some strings, like "1" or "false".

For example, it'd be impossible to correctly set package.edition in a Cargo.toml file:

$ target/debug/toml set --overwrite Cargo.toml package.edition 2018

$ git diff -U0
diff --git a/Cargo.toml b/Cargo.toml
index 2f232cf98..ac60e2325 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10 +10 @@ license = "MIT"
-edition = "2018"
+edition = 2018

$ cargo check
error: failed to parse manifest at `/home/greg/w/toml-cli/Cargo.toml`

Caused by:
  data did not match any variant of untagged enum MaybeWorkspace for key `package.edition`

… and in a followup comment:

Instead, what would you think about having toml set take a flag to tell it how it should parse the value? Probably "string" would still be the default -- I feel like that's probably the most common.

So e.g.

toml set foo.toml x asdf   # a string
toml set foo.toml x --string asdf  # the same thing, explicitly

toml set foo.toml x 2018  # still a string: `x = "2018"`
toml set foo.toml x --int 2018  # an int: `x = 2018`
toml set foo.toml x --int asdf  # error

toml set foo.toml x --bool false
toml set foo.toml x --bool asdf  # error
@liubin
Copy link
Contributor Author

liubin commented Dec 3, 2022

And also #13 (comment)

@gnprice gnprice changed the title Support set data type Set int and bool values as well as strings Dec 3, 2022
@gnprice
Copy link
Owner

gnprice commented Dec 3, 2022

Thanks for filing these issues! Added that second comment into the description, and also edited the title to narrow the scope slightly: we might have future issues to add support for setting floats, and datetimes, and even whole tables and arrays (perhaps supplied in JSON form?), but this one can be about just integers and booleans.

@gnprice
Copy link
Owner

gnprice commented Dec 4, 2022

#10 is a related issue, for setting arrays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants