mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
Try to preserve the ordering of elements in from toml (#13045)
# Description Enable the `preserve_order` feature of the `toml` crate to preserve the ordering of elements when converting from/to toml. Additionally, use `to_string_pretty()` instead of `to_string()` in `to toml`. This displays arrays on multiple lines instead of one big single line. I'm not sure if this one is a good idea or not... Happy to remove this from this PR if it's not. # User-Facing Changes The order of elements will be different when using `from toml`. The formatting of arrays will also be different when using `to toml`. For example: - before ``` ❯ "foo=1\nbar=2\ndoo=3" | from toml ╭─────┬───╮ │ bar │ 2 │ │ doo │ 3 │ │ foo │ 1 │ ╰─────┴───╯ ❯ {a: [a b c d]} | to toml a = ["a", "b", "c", "d"] ``` - after ``` ❯ "foo=1\nbar=2\ndoo=3" | from toml ╭─────┬───╮ │ foo │ 1 │ │ bar │ 2 │ │ doo │ 3 │ ╰─────┴───╯ ❯ {a: [a b c d]} | to toml a = [ "a", "b", "c", "d", ] ``` # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🔴 `toolkit test` - ⚫ `toolkit test stdlib` # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
This commit is contained in:
parent
3f0db11ae5
commit
65911c125c
4 changed files with 696 additions and 695 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -6068,6 +6068,7 @@ version = "0.8.12"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e9dd1545e8208b4a5af1aa9bbd0b4cf7e9ea08fabc5d0a5c67fcaafa17433aa3"
|
||||
dependencies = [
|
||||
"indexmap",
|
||||
"serde",
|
||||
"serde_spanned",
|
||||
"toml_datetime",
|
||||
|
|
|
@ -86,7 +86,7 @@ sysinfo = { workspace = true }
|
|||
tabled = { workspace = true, features = ["color"], default-features = false }
|
||||
terminal_size = { workspace = true }
|
||||
titlecase = { workspace = true }
|
||||
toml = { workspace = true }
|
||||
toml = { workspace = true, features = ["preserve_order"]}
|
||||
unicode-segmentation = { workspace = true }
|
||||
ureq = { workspace = true, default-features = false, features = ["charset", "gzip", "json", "native-tls"] }
|
||||
url = { workspace = true }
|
||||
|
|
|
@ -24,7 +24,7 @@ impl Command for ToToml {
|
|||
vec![Example {
|
||||
description: "Outputs an TOML string representing the contents of this record",
|
||||
example: r#"{foo: 1 bar: 'qwe'} | to toml"#,
|
||||
result: Some(Value::test_string("bar = \"qwe\"\nfoo = 1\n")),
|
||||
result: Some(Value::test_string("foo = 1\nbar = \"qwe\"\n")),
|
||||
}]
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ fn toml_into_pipeline_data(
|
|||
value_type: Type,
|
||||
span: Span,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
match toml::to_string(&toml_value) {
|
||||
match toml::to_string_pretty(&toml_value) {
|
||||
Ok(serde_toml_string) => Ok(Value::string(serde_toml_string, span).into_pipeline_data()),
|
||||
_ => Ok(Value::error(
|
||||
ShellError::CantConvert {
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue