mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
add "to nuon" enumeration of possible styles (#12591)
# Description
in order to change the style of the _serialized_ NUON data,
`nuon::to_nuon` takes three mutually exclusive arguments, `raw: bool`,
`tabs: Option<usize>` and `indent: Option<usize>` 🤔
this begs to use an enumeration with all possible alternatives, right?
this PR changes the signature of `nuon::to_nuon` to use `nuon::ToStyle`
which has three variants
- `Raw`: no newlines
- `Tabs(n: usize)`: newlines and `n` tabulations as indent
- `Spaces(n: usize)`: newlines and `n` spaces as indent
# User-Facing Changes
the signature of `nuon::to_nuon` changes from
```rust
to_nuon(
input: &Value,
raw: bool,
tabs: Option<usize>,
indent: Option<usize>,
span: Option<Span>,
) -> Result<String, ShellError>
```
to
```rust
to_nuon(
input: &Value,
style: ToStyle,
span: Option<Span>
) -> Result<String, ShellError>
```
# Tests + Formatting
# After Submitting
This commit is contained in:
@ -42,14 +42,20 @@ impl Command for ToNuon {
|
||||
call: &Call,
|
||||
input: PipelineData,
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
let raw = call.has_flag(engine_state, stack, "raw")?;
|
||||
let tabs: Option<usize> = call.get_flag(engine_state, stack, "tabs")?;
|
||||
let indent: Option<usize> = call.get_flag(engine_state, stack, "indent")?;
|
||||
let style = if call.has_flag(engine_state, stack, "raw")? {
|
||||
nuon::ToStyle::Raw
|
||||
} else if let Some(t) = call.get_flag(engine_state, stack, "tabs")? {
|
||||
nuon::ToStyle::Tabs(t)
|
||||
} else if let Some(i) = call.get_flag(engine_state, stack, "indent")? {
|
||||
nuon::ToStyle::Spaces(i)
|
||||
} else {
|
||||
nuon::ToStyle::Raw
|
||||
};
|
||||
|
||||
let span = call.head;
|
||||
let value = input.into_value(span);
|
||||
|
||||
match nuon::to_nuon(&value, raw, tabs, indent, Some(span)) {
|
||||
match nuon::to_nuon(&value, style, Some(span)) {
|
||||
Ok(serde_nuon_string) => {
|
||||
Ok(Value::string(serde_nuon_string, span).into_pipeline_data())
|
||||
}
|
||||
|
Reference in New Issue
Block a user