Skip to content

Better support for (sub)command deprecations #7530

@sholderbach

Description

@sholderbach

Related problem

Currently deprecating a subcommand like url path or math eval is nearly impossible to get right.

For single word commands we have the deprecated_commands() function that will emit a ShellError::DeprecatedCommand with suggestion directly when the old command is not found in scope anymore.

pub fn deprecated_commands() -> HashMap<String, String> {
HashMap::from([
("keep".to_string(), "take".to_string()),
("match".to_string(), "find".to_string()),
("nth".to_string(), "select".to_string()),
("pivot".to_string(), "transpose".to_string()),
("unalias".to_string(), "hide".to_string()),
("all?".to_string(), "all".to_string()),
("any?".to_string(), "any".to_string()),
("empty?".to_string(), "is-empty".to_string()),
(
"build-string".to_string(),
"str join'/'string concatenation with '+'".to_string(),
),
])

This solution doesn't directly translate to nu subcommands.
Most of them have a base command providing an overview help (e.g. math, str). Thus just removing the subcommand will return an error about some additional positional. Currently deprecated_commands() doesn't support space separated commands.

For some subcommands we have stub commands that just return a deprecation notice:

https://github.com/nushell/nushell/tree/main/crates/nu-command/src/deprecated

But this has another limitation, as soon as you add arguments:

/home/stefan/nushell> math eval "1+2"
Error: nu::parser::extra_positional (link)

  × Extra positional argument.
   ╭─[entry #18:1:1]
 1 │ math eval "1+2"
   ·           ──┬──
   ·             ╰── extra positional argument
   ╰────
  help: Usage: math eval

Now the parser takes precedence and tells you that the call doesn't match the now empty signature. (For positionals you could take a rest but flags are still in flux in that regard)

Describe the solution you'd like

You can deprecate subcommands and adding arguments to a deprecated subcommand doesn't change the error.

Describe alternatives you've considered

No response

Additional context and details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:error-unhelpfulThe error message you observe is not helpful to identify the problemcategory:enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions