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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reject incombatible flag combinations in to nuon #12595

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sholderbach
Copy link
Member

Description

Follow up to #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.

User-Facing Changes

Ineffective combinations of flags will now return a ShellError::IncompatibleParameters instead of returning output for which the exact behavior was previously undefined.

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.
This was introduced as nushell#8366 introduced a logic to have a priority of
those flags (and have the `--raw` flag purely to match the flags on `to
json`)
@sholderbach
Copy link
Member Author

sholderbach commented Apr 20, 2024

Marking as draft for a second as with this mutual excusion scheme --raw becomes actually useless.

#8366 introduced it with the implicit precedence scheme for --tabs and --indent so you can override those optional named ones with a --raw. I think the implicit precedence rule for --tabs/--indent is a bad design. On the other hand there may be the assumption that you can override an otherwise configured to nuon call like that with --raw. If we go for maximum clarity on the mutually exclusive options --raw should be removed as it currently has no effect alone.

@sholderbach sholderbach marked this pull request as draft April 20, 2024 18:34
@sholderbach sholderbach added needs-design this feature requires design pr:breaking-change This PR implies a change affecting users and has to be noted in the release notes pr:commands This PR changes our commands in some way labels Apr 20, 2024
@fdncred
Copy link
Collaborator

fdncred commented Apr 20, 2024

Whatever we do here probably needs to be done for to json as well, so we can be consistent. I don't see any other --raw parameters on the to commands but seems like to xml and to yaml would be equally deserving of whatever is decided here.

In general, I think we should have a default (which I think is raw here maybe?), and then a way to override the default with the number of indents and then whether those indents are tabs or spaces.

@sholderbach
Copy link
Member Author

The difference for to json is that there --raw does have an effect.
Our nu-json fork from hjson outputs with linebreaks and gratuitous whitespace, and the flag removed that (before #11900 switched to serde_json as a serializer in this case, by actually pulling out whitespace afterwards).
to json --indent 2 is the implied default value. So there all option could fully be mutually exclusive.

The one argument for keeping --raw here would be that you could more cheaply toggle between human or machine output in programmatic Nu code.

def my_func[--human-readable] {
  ls | first 3 | to nuon --indent 4 --raw=(not $human_readable)
}

At the same time for interactive use and general readability having these implicit overrides is less fortunate, if you don't start writing documentation sermons like in the description of #8366

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-design this feature requires design pr:breaking-change This PR implies a change affecting users and has to be noted in the release notes pr:commands This PR changes our commands in some way
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants