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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

add "to nuon" enumeration of possible styles #12591

Merged
merged 5 commits into from
Apr 20, 2024

Conversation

amtoine
Copy link
Member

@amtoine amtoine commented Apr 20, 2024

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

to_nuon(
    input: &Value,
    raw: bool,
    tabs: Option<usize>,
    indent: Option<usize>,
    span: Option<Span>,
) -> Result<String, ShellError>

to

to_nuon(
    input: &Value,
    style: ToStyle,
    span: Option<Span>
) -> Result<String, ShellError>

Tests + Formatting

After Submitting

@amtoine amtoine changed the title add "to nuon" enumeration of possible style add "to nuon" enumeration of possible styles Apr 20, 2024
@amtoine
Copy link
Member Author

amtoine commented Apr 20, 2024

let's land that, this opens the door for new styles in the future, without polluting the signature of nuon::to_nuon :)

@amtoine
Copy link
Member Author

amtoine commented Apr 20, 2024

(has been viewed in private btw, not landing this out of thin air 馃槈)

@amtoine amtoine merged commit be5ed32 into nushell:main Apr 20, 2024
15 checks passed
@amtoine amtoine deleted the nu-nuon-to-style branch April 20, 2024 09:40
amtoine added a commit to amtoine/nu_plugin_explore that referenced this pull request Apr 20, 2024
related to
- nushell/nushell#12591

## description
- bumps the Nushell dependencies and the package to
nushell/nushell@be5ed32
- uses the new `nuon::ToStyle::Raw`
@hustcer hustcer added this to the v0.93.0 milestone Apr 20, 2024
crates/nu-command/src/formats/to/nuon.rs Show resolved Hide resolved
} else if let Some(i) = call.get_flag(engine_state, stack, "indent")? {
nuon::ToStyle::Spaces(i)
} else {
nuon::ToStyle::Raw
Copy link
Member

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?

Copy link
Member Author

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

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)
};

Copy link
Member

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.

Copy link
Member Author

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

sholderbach added a commit to sholderbach/nushell that referenced this pull request Apr 20, 2024
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.
fdncred pushed a commit that referenced this pull request Apr 21, 2024
follow-up to
- #12591

cc/ @fdncred 

# Description
there was a typo in the doc of `nuon::ToStyle`.

# User-Facing Changes

# Tests + Formatting

# After Submitting
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

Successfully merging this pull request may close these issues.

None yet

4 participants