-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Better support for (sub)command deprecations #7530
Description
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.
nushell/crates/nu-command/src/deprecated/deprecated_commands.rs
Lines 7 to 21 in 5f48452
| 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