mirror of
https://github.com/nushell/nushell.git
synced 2025-08-10 12:58:11 +02:00
feat: make to nuon raw option remove all white space (#15609)
# Description Fixes #9942 This adds a new `--minified` flag to `to nuon` which removes all possible white space. I added an example test to demonstrate the functionality. # User-Facing Changes New flag becomes available to the user.
This commit is contained in:
@ -218,7 +218,7 @@ fn generate_key(engine_state: &EngineState, item: &ValueCounter) -> Result<Strin
|
||||
nuon::to_nuon(
|
||||
engine_state,
|
||||
&value,
|
||||
nuon::ToStyle::Raw,
|
||||
nuon::ToStyle::Default,
|
||||
Some(Span::unknown()),
|
||||
false,
|
||||
)
|
||||
|
@ -35,6 +35,14 @@ impl Command for FromNuon {
|
||||
"b" => Value::test_list(vec![Value::test_int(1), Value::test_int(2)]),
|
||||
})),
|
||||
},
|
||||
Example {
|
||||
example: "'{a:1,b:[1,2]}' | from nuon",
|
||||
description: "Converts raw nuon formatted string to table",
|
||||
result: Some(Value::test_record(record! {
|
||||
"a" => Value::test_int(1),
|
||||
"b" => Value::test_list(vec![Value::test_int(1), Value::test_int(2)]),
|
||||
})),
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ impl Command for ToNuon {
|
||||
.input_output_types(vec![(Type::Any, Type::String)])
|
||||
.switch(
|
||||
"raw",
|
||||
"remove all of the whitespace (default behaviour and overwrites -i and -t)",
|
||||
"remove all of the whitespace (overwrites -i and -t)",
|
||||
Some('r'),
|
||||
)
|
||||
.named(
|
||||
@ -60,7 +60,7 @@ impl Command for ToNuon {
|
||||
} else if let Some(i) = call.get_flag(engine_state, stack, "indent")? {
|
||||
nuon::ToStyle::Spaces(i)
|
||||
} else {
|
||||
nuon::ToStyle::Raw
|
||||
nuon::ToStyle::Default
|
||||
};
|
||||
|
||||
let span = call.head;
|
||||
@ -90,12 +90,17 @@ impl Command for ToNuon {
|
||||
Example {
|
||||
description: "Overwrite any set option with --raw",
|
||||
example: "[1 2 3] | to nuon --indent 2 --raw",
|
||||
result: Some(Value::test_string("[1, 2, 3]"))
|
||||
result: Some(Value::test_string("[1,2,3]"))
|
||||
},
|
||||
Example {
|
||||
description: "A more complex record with multiple data types",
|
||||
example: "{date: 2000-01-01, data: [1 [2 3] 4.56]} | to nuon --indent 2",
|
||||
result: Some(Value::test_string("{\n date: 2000-01-01T00:00:00+00:00,\n data: [\n 1,\n [\n 2,\n 3\n ],\n 4.56\n ]\n}"))
|
||||
},
|
||||
Example {
|
||||
description: "A more complex record with --raw",
|
||||
example: "{date: 2000-01-01, data: [1 [2 3] 4.56]} | to nuon --raw",
|
||||
result: Some(Value::test_string("{date:2000-01-01T00:00:00+00:00,data:[1,[2,3],4.56]}"))
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user