Skip to content

Better support for (sub)command deprecations #7530

Closed

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

Activity

  1. added
    category:enhancement
    A:error-unhelpful
    on Dec 19, 2022
  2. 132ikl commented on Oct 2, 2025

    @132ikl
    Member

    I think we can probably close this since when we deprecate commands now, it's not a breaking change. I think the idea before was that "deprecated" commands weren't supposed to work still, just give a message telling you it was deprecated. Now, the deprecated commands work the same as before being deprecated, and stop working altogether with no error once removed. I think I'll close this but if I'm misunderstanding @sholderbach then we can reopen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:error-unhelpfulcategory:enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions