-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
add "to nuon" enumeration of possible styles #12591
Conversation
let's land that, this opens the door for new styles in the future, without polluting the signature of |
(has been viewed in private btw, not landing this out of thin air 馃槈) |
related to - nushell/nushell#12591 ## description - bumps the Nushell dependencies and the package to nushell/nushell@be5ed32 - uses the new `nuon::ToStyle::Raw`
} else if let Some(i) = call.get_flag(engine_state, stack, "indent")? { | ||
nuon::ToStyle::Spaces(i) | ||
} else { | ||
nuon::ToStyle::Raw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure when the default and --raw
became the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was like this before i created the nuon
crate 馃槈
55edef5 is the commit of the crate creation and fac2f43 is the commit before
nushell/crates/nu-command/src/formats/to/nuon.rs
Lines 58 to 66 in fac2f43
let nuon_result = if raw { | |
value_to_string(&value, span, 0, None) | |
} else if let Some(tab_count) = tabs { | |
value_to_string(&value, span, 0, Some(&"\t".repeat(tab_count))) | |
} else if let Some(indent) = indent { | |
value_to_string(&value, span, 0, Some(&" ".repeat(indent))) | |
} else { | |
value_to_string(&value, span, 0, None) | |
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The origin of --raw
being equal to the default is in #8366 and there in turn in an attempt to mirror to json
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahah yeah that was me lol
Follow up to nushell#12591 Ensure an error is shown. `.expect` is fine here as the precondition of reaching each branch is explicitly that this flag has been found. Only extra care has to be taken when changing the flag name. But that is the general risk of this stringly typed API.
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>
andindent: Option<usize>
馃this begs to use an enumeration with all possible alternatives, right?
this PR changes the signature of
nuon::to_nuon
to usenuon::ToStyle
which has three variantsRaw
: no newlinesTabs(n: usize)
: newlines andn
tabulations as indentSpaces(n: usize)
: newlines andn
spaces as indentUser-Facing Changes
the signature of
nuon::to_nuon
changes fromto
Tests + Formatting
After Submitting