forked from extern/nushell
Delete most deprecated commands (#6260)
This commit is contained in:
parent
aaf5684f9c
commit
cd0a04f02a
@ -416,7 +416,6 @@ pub fn create_default_context() -> EngineState {
|
||||
Hash,
|
||||
HashMd5::default(),
|
||||
HashSha256::default(),
|
||||
HashBase64,
|
||||
};
|
||||
|
||||
// Experimental
|
||||
@ -427,17 +426,11 @@ pub fn create_default_context() -> EngineState {
|
||||
|
||||
// Deprecated
|
||||
bind_command! {
|
||||
PivotDeprecated,
|
||||
HashBase64,
|
||||
StrDatetimeDeprecated,
|
||||
StrDecimalDeprecated,
|
||||
StrIntDeprecated,
|
||||
MatchDeprecated,
|
||||
NthDeprecated,
|
||||
UnaliasDeprecated,
|
||||
StrFindReplaceDeprecated,
|
||||
KeepDeprecated,
|
||||
KeepUntilDeprecated,
|
||||
KeepWhileDeprecated,
|
||||
};
|
||||
|
||||
#[cfg(feature = "plugin")]
|
||||
|
15
crates/nu-command/src/deprecated/deprecated_commands.rs
Normal file
15
crates/nu-command/src/deprecated/deprecated_commands.rs
Normal file
@ -0,0 +1,15 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// Return map of <deprecated_command_name, new_command_name>
|
||||
/// This covers simple deprecated commands nicely, but it's not great for deprecating
|
||||
/// subcommands like `foo bar` where `foo` is still a valid command.
|
||||
/// For those, it's currently easiest to have a "stub" command that just returns an error.
|
||||
pub fn deprecated_commands() -> HashMap<String, String> {
|
||||
let mut commands = HashMap::new();
|
||||
commands.insert("keep".to_string(), "take".to_string());
|
||||
commands.insert("match".to_string(), "find".to_string());
|
||||
commands.insert("nth".to_string(), "select".to_string());
|
||||
commands.insert("pivot".to_string(), "transpose".to_string());
|
||||
commands.insert("unalias".to_string(), "hide".to_string());
|
||||
commands
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EngineState, Stack},
|
||||
Category, PipelineData, Signature,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct KeepDeprecated;
|
||||
|
||||
impl Command for KeepDeprecated {
|
||||
fn name(&self) -> &str {
|
||||
"keep"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build(self.name()).category(Category::Deprecated)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Deprecated command"
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
_engine_state: &EngineState,
|
||||
_stack: &mut Stack,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
Err(nu_protocol::ShellError::DeprecatedCommand(
|
||||
self.name().to_string(),
|
||||
"take".to_string(),
|
||||
call.head,
|
||||
))
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EngineState, Stack},
|
||||
Category, PipelineData, Signature,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct KeepUntilDeprecated;
|
||||
|
||||
impl Command for KeepUntilDeprecated {
|
||||
fn name(&self) -> &str {
|
||||
"keep until"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build(self.name()).category(Category::Deprecated)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Deprecated command"
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
_engine_state: &EngineState,
|
||||
_stack: &mut Stack,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
Err(nu_protocol::ShellError::DeprecatedCommand(
|
||||
self.name().to_string(),
|
||||
"take until".to_string(),
|
||||
call.head,
|
||||
))
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EngineState, Stack},
|
||||
Category, PipelineData, Signature,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct KeepWhileDeprecated;
|
||||
|
||||
impl Command for KeepWhileDeprecated {
|
||||
fn name(&self) -> &str {
|
||||
"keep while"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build(self.name()).category(Category::Deprecated)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Deprecated command"
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
_engine_state: &EngineState,
|
||||
_stack: &mut Stack,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
Err(nu_protocol::ShellError::DeprecatedCommand(
|
||||
self.name().to_string(),
|
||||
"take while".to_string(),
|
||||
call.head,
|
||||
))
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EngineState, Stack},
|
||||
Category, PipelineData, Signature,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct MatchDeprecated;
|
||||
|
||||
impl Command for MatchDeprecated {
|
||||
fn name(&self) -> &str {
|
||||
"match"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build(self.name()).category(Category::Deprecated)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Deprecated command"
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
_engine_state: &EngineState,
|
||||
_stack: &mut Stack,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
Err(nu_protocol::ShellError::DeprecatedCommand(
|
||||
self.name().to_string(),
|
||||
"find".to_string(),
|
||||
call.head,
|
||||
))
|
||||
}
|
||||
}
|
@ -1,25 +1,13 @@
|
||||
mod deprecated_commands;
|
||||
mod hash_base64;
|
||||
mod keep_;
|
||||
mod keep_until;
|
||||
mod keep_while;
|
||||
mod match_;
|
||||
mod nth;
|
||||
mod pivot;
|
||||
mod str_datetime;
|
||||
mod str_decimal;
|
||||
mod str_find_replace;
|
||||
mod str_int;
|
||||
mod unalias;
|
||||
|
||||
pub use deprecated_commands::*;
|
||||
pub use hash_base64::HashBase64;
|
||||
pub use keep_::KeepDeprecated;
|
||||
pub use keep_until::KeepUntilDeprecated;
|
||||
pub use keep_while::KeepWhileDeprecated;
|
||||
pub use match_::MatchDeprecated;
|
||||
pub use nth::NthDeprecated;
|
||||
pub use pivot::PivotDeprecated;
|
||||
pub use str_datetime::StrDatetimeDeprecated;
|
||||
pub use str_decimal::StrDecimalDeprecated;
|
||||
pub use str_find_replace::StrFindReplaceDeprecated;
|
||||
pub use str_int::StrIntDeprecated;
|
||||
pub use unalias::UnaliasDeprecated;
|
||||
|
@ -1,36 +0,0 @@
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EngineState, Stack},
|
||||
Category, PipelineData, Signature,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct NthDeprecated;
|
||||
|
||||
impl Command for NthDeprecated {
|
||||
fn name(&self) -> &str {
|
||||
"nth"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build(self.name()).category(Category::Deprecated)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Deprecated command"
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
_engine_state: &EngineState,
|
||||
_stack: &mut Stack,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
Err(nu_protocol::ShellError::DeprecatedCommand(
|
||||
self.name().to_string(),
|
||||
"select".to_string(),
|
||||
call.head,
|
||||
))
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EngineState, Stack},
|
||||
Category, PipelineData, Signature,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct PivotDeprecated;
|
||||
|
||||
impl Command for PivotDeprecated {
|
||||
fn name(&self) -> &str {
|
||||
"pivot"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build(self.name()).category(Category::Deprecated)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Deprecated command"
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
_engine_state: &EngineState,
|
||||
_stack: &mut Stack,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
Err(nu_protocol::ShellError::DeprecatedCommand(
|
||||
self.name().to_string(),
|
||||
"transpose".to_string(),
|
||||
call.head,
|
||||
))
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
use nu_protocol::{
|
||||
ast::Call,
|
||||
engine::{Command, EngineState, Stack},
|
||||
Category, PipelineData, Signature,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct UnaliasDeprecated;
|
||||
|
||||
impl Command for UnaliasDeprecated {
|
||||
fn name(&self) -> &str {
|
||||
"unalias"
|
||||
}
|
||||
|
||||
fn signature(&self) -> Signature {
|
||||
Signature::build(self.name()).category(Category::Deprecated)
|
||||
}
|
||||
|
||||
fn usage(&self) -> &str {
|
||||
"Deprecated command"
|
||||
}
|
||||
|
||||
fn run(
|
||||
&self,
|
||||
_engine_state: &EngineState,
|
||||
_stack: &mut Stack,
|
||||
call: &Call,
|
||||
_input: PipelineData,
|
||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||
Err(nu_protocol::ShellError::DeprecatedCommand(
|
||||
self.name().to_string(),
|
||||
"hide".to_string(),
|
||||
call.head,
|
||||
))
|
||||
}
|
||||
}
|
@ -159,6 +159,21 @@ impl ExternalCommand {
|
||||
|
||||
match child {
|
||||
Err(err) => {
|
||||
// recommend a replacement if the user tried a deprecated command
|
||||
let command_name_lower = self.name.item.to_lowercase();
|
||||
let deprecated = crate::deprecated_commands();
|
||||
if deprecated.contains_key(&command_name_lower) {
|
||||
let replacement = match deprecated.get(&command_name_lower) {
|
||||
Some(s) => s.clone(),
|
||||
None => "".to_string(),
|
||||
};
|
||||
return Err(ShellError::DeprecatedCommand(
|
||||
command_name_lower,
|
||||
replacement,
|
||||
self.name.span,
|
||||
));
|
||||
}
|
||||
|
||||
// If we try to run an external but can't, there's a good chance
|
||||
// that the user entered the wrong command name
|
||||
let suggestion = suggest_command(&self.name.item, engine_state);
|
||||
|
Loading…
Reference in New Issue
Block a user