diff --git a/crates/nu-command/src/default_context.rs b/crates/nu-command/src/default_context.rs index e2bde0420a..78b7f72d07 100644 --- a/crates/nu-command/src/default_context.rs +++ b/crates/nu-command/src/default_context.rs @@ -343,6 +343,18 @@ pub fn create_default_context(cwd: impl AsRef) -> EngineState { ViewSource, }; + // Deprecated + bind_command! { + InsertDeprecated, + PivotDeprecated, + StrDecimalDeprecated, + StrIntDeprecated, + NthDeprecated, + }; + + #[cfg(feature = "dataframe")] + bind_command!(DataframeDeprecated); + #[cfg(feature = "plugin")] bind_command!(Register); diff --git a/crates/nu-command/src/deprecated/dataframe.rs b/crates/nu-command/src/deprecated/dataframe.rs new file mode 100644 index 0000000000..949a425ea5 --- /dev/null +++ b/crates/nu-command/src/deprecated/dataframe.rs @@ -0,0 +1,36 @@ +use nu_protocol::{ + ast::Call, + engine::{Command, EngineState, Stack}, + Category, PipelineData, Signature, +}; + +#[derive(Clone)] +pub struct DataframeDeprecated; + +impl Command for DataframeDeprecated { + fn name(&self) -> &str { + "dataframe" + } + + 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(), + "dfr".to_string(), + call.head, + )) + } +} diff --git a/crates/nu-command/src/deprecated/insert.rs b/crates/nu-command/src/deprecated/insert.rs new file mode 100644 index 0000000000..17075b7598 --- /dev/null +++ b/crates/nu-command/src/deprecated/insert.rs @@ -0,0 +1,36 @@ +use nu_protocol::{ + ast::Call, + engine::{Command, EngineState, Stack}, + Category, PipelineData, Signature, +}; + +#[derive(Clone)] +pub struct InsertDeprecated; + +impl Command for InsertDeprecated { + fn name(&self) -> &str { + "insert" + } + + 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(), + "update".to_string(), + call.head, + )) + } +} diff --git a/crates/nu-command/src/deprecated/mod.rs b/crates/nu-command/src/deprecated/mod.rs new file mode 100644 index 0000000000..1533ced003 --- /dev/null +++ b/crates/nu-command/src/deprecated/mod.rs @@ -0,0 +1,17 @@ +mod insert; +mod nth; +mod pivot; +mod str_decimal; +mod str_int; + +pub use insert::InsertDeprecated; +pub use nth::NthDeprecated; +pub use pivot::PivotDeprecated; +pub use str_decimal::StrDecimalDeprecated; +pub use str_int::StrIntDeprecated; + +#[cfg(feature = "dataframe")] +mod dataframe; + +#[cfg(feature = "dataframe")] +pub use dataframe::DataframeDeprecated; diff --git a/crates/nu-command/src/deprecated/nth.rs b/crates/nu-command/src/deprecated/nth.rs new file mode 100644 index 0000000000..c51b6bcf2b --- /dev/null +++ b/crates/nu-command/src/deprecated/nth.rs @@ -0,0 +1,36 @@ +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 new file mode 100644 index 0000000000..394749060a --- /dev/null +++ b/crates/nu-command/src/deprecated/pivot.rs @@ -0,0 +1,36 @@ +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/str_decimal.rs b/crates/nu-command/src/deprecated/str_decimal.rs new file mode 100644 index 0000000000..25e24be95e --- /dev/null +++ b/crates/nu-command/src/deprecated/str_decimal.rs @@ -0,0 +1,36 @@ +use nu_protocol::{ + ast::Call, + engine::{Command, EngineState, Stack}, + Category, PipelineData, Signature, +}; + +#[derive(Clone)] +pub struct StrDecimalDeprecated; + +impl Command for StrDecimalDeprecated { + fn name(&self) -> &str { + "str to-decimal" + } + + 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(), + "into decimal".to_string(), + call.head, + )) + } +} diff --git a/crates/nu-command/src/deprecated/str_int.rs b/crates/nu-command/src/deprecated/str_int.rs new file mode 100644 index 0000000000..2c4e68b08e --- /dev/null +++ b/crates/nu-command/src/deprecated/str_int.rs @@ -0,0 +1,36 @@ +use nu_protocol::{ + ast::Call, + engine::{Command, EngineState, Stack}, + Category, PipelineData, Signature, +}; + +#[derive(Clone)] +pub struct StrIntDeprecated; + +impl Command for StrIntDeprecated { + fn name(&self) -> &str { + "str to-int" + } + + 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(), + "into int".to_string(), + call.head, + )) + } +} diff --git a/crates/nu-command/src/lib.rs b/crates/nu-command/src/lib.rs index 3caca19722..29863951fb 100644 --- a/crates/nu-command/src/lib.rs +++ b/crates/nu-command/src/lib.rs @@ -2,6 +2,7 @@ mod conversions; mod core_commands; mod date; mod default_context; +mod deprecated; mod env; mod example_test; mod experimental; @@ -24,6 +25,7 @@ pub use conversions::*; pub use core_commands::*; pub use date::*; pub use default_context::*; +pub use deprecated::*; pub use env::*; #[cfg(test)] pub use example_test::test_examples; diff --git a/crates/nu-protocol/src/shell_error.rs b/crates/nu-protocol/src/shell_error.rs index b02d4f3814..182b9e7b71 100644 --- a/crates/nu-protocol/src/shell_error.rs +++ b/crates/nu-protocol/src/shell_error.rs @@ -267,6 +267,14 @@ pub enum ShellError { #[error("{0}")] #[diagnostic(help("{1}"))] LabeledError(String, String), + + #[error("Deprecated command {0}")] + #[diagnostic(code(nu::shell::deprecated_command), url(docsrs))] + DeprecatedCommand( + String, + String, + #[label = "{0} is deprecated. Instead use {1}"] Span, + ), } impl From for ShellError { diff --git a/crates/nu-protocol/src/signature.rs b/crates/nu-protocol/src/signature.rs index 6ea31f6b4c..bfbb438ae7 100644 --- a/crates/nu-protocol/src/signature.rs +++ b/crates/nu-protocol/src/signature.rs @@ -52,6 +52,7 @@ pub enum Category { Hash, Generators, Custom(String), + Deprecated, } impl std::fmt::Display for Category { @@ -77,6 +78,7 @@ impl std::fmt::Display for Category { Category::Hash => "hash", Category::Generators => "generators", Category::Custom(name) => name, + Category::Deprecated => "deprecated", }; write!(f, "{}", msg)