diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index 747ee873eb..34b13b8243 100644 --- a/crates/nu-command/src/default_context.rs +++ b/crates/nu-command/src/default_context.rs @@ -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")] diff --git a/crates/nu-command/src/deprecated/deprecated_commands.rs b/crates/nu-command/src/deprecated/deprecated_commands.rs new file mode 100644 index 0000000000..4ba9d167a6 --- /dev/null +++ b/crates/nu-command/src/deprecated/deprecated_commands.rs @@ -0,0 +1,15 @@ +use std::collections::HashMap; + +/// Return map of +/// 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 { + 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 +} diff --git a/crates/nu-command/src/deprecated/keep_.rs b/crates/nu-command/src/deprecated/keep_.rs deleted file mode 100644 index e152f8ab09..0000000000 --- a/crates/nu-command/src/deprecated/keep_.rs +++ /dev/null @@ -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 { - Err(nu_protocol::ShellError::DeprecatedCommand( - self.name().to_string(), - "take".to_string(), - call.head, - )) - } -} diff --git a/crates/nu-command/src/deprecated/keep_until.rs b/crates/nu-command/src/deprecated/keep_until.rs deleted file mode 100644 index 003c5c0dbf..0000000000 --- a/crates/nu-command/src/deprecated/keep_until.rs +++ /dev/null @@ -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 { - Err(nu_protocol::ShellError::DeprecatedCommand( - self.name().to_string(), - "take until".to_string(), - call.head, - )) - } -} diff --git a/crates/nu-command/src/deprecated/keep_while.rs b/crates/nu-command/src/deprecated/keep_while.rs deleted file mode 100644 index 94d916d532..0000000000 --- a/crates/nu-command/src/deprecated/keep_while.rs +++ /dev/null @@ -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 { - Err(nu_protocol::ShellError::DeprecatedCommand( - self.name().to_string(), - "take while".to_string(), - call.head, - )) - } -} diff --git a/crates/nu-command/src/deprecated/match_.rs b/crates/nu-command/src/deprecated/match_.rs deleted file mode 100644 index 9431f97b08..0000000000 --- a/crates/nu-command/src/deprecated/match_.rs +++ /dev/null @@ -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 { - Err(nu_protocol::ShellError::DeprecatedCommand( - self.name().to_string(), - "find".to_string(), - call.head, - )) - } -} diff --git a/crates/nu-command/src/deprecated/mod.rs b/crates/nu-command/src/deprecated/mod.rs index 3caa9c4ffc..10a2194005 100644 --- a/crates/nu-command/src/deprecated/mod.rs +++ b/crates/nu-command/src/deprecated/mod.rs @@ -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; diff --git a/crates/nu-command/src/deprecated/nth.rs b/crates/nu-command/src/deprecated/nth.rs deleted file mode 100644 index c51b6bcf2b..0000000000 --- a/crates/nu-command/src/deprecated/nth.rs +++ /dev/null @@ -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 { - Err(nu_protocol::ShellError::DeprecatedCommand( - self.name().to_string(), - "select".to_string(), - call.head, - )) - } -} diff --git a/crates/nu-command/src/deprecated/pivot.rs b/crates/nu-command/src/deprecated/pivot.rs deleted file mode 100644 index 394749060a..0000000000 --- a/crates/nu-command/src/deprecated/pivot.rs +++ /dev/null @@ -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 { - Err(nu_protocol::ShellError::DeprecatedCommand( - self.name().to_string(), - "transpose".to_string(), - call.head, - )) - } -} diff --git a/crates/nu-command/src/deprecated/unalias.rs b/crates/nu-command/src/deprecated/unalias.rs deleted file mode 100644 index 6cffc40ceb..0000000000 --- a/crates/nu-command/src/deprecated/unalias.rs +++ /dev/null @@ -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 { - Err(nu_protocol::ShellError::DeprecatedCommand( - self.name().to_string(), - "hide".to_string(), - call.head, - )) - } -} diff --git a/crates/nu-command/src/system/run_external.rs b/crates/nu-command/src/system/run_external.rs index 354959548e..3392b9a038 100644 --- a/crates/nu-command/src/system/run_external.rs +++ b/crates/nu-command/src/system/run_external.rs @@ -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);