diff --git a/crates/nu-cmd-lang/src/core_commands/def_env.rs b/crates/nu-cmd-lang/src/core_commands/def_env.rs deleted file mode 100644 index 4d967d7b6d..0000000000 --- a/crates/nu-cmd-lang/src/core_commands/def_env.rs +++ /dev/null @@ -1,65 +0,0 @@ -use nu_protocol::ast::Call; -use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{ - Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value, -}; - -#[derive(Clone)] -pub struct DefEnv; - -impl Command for DefEnv { - fn name(&self) -> &str { - "def-env" - } - - fn usage(&self) -> &str { - "Define a custom command, which participates in the caller environment." - } - - fn signature(&self) -> nu_protocol::Signature { - Signature::build("def-env") - .input_output_types(vec![(Type::Nothing, Type::Nothing)]) - .required("def_name", SyntaxShape::String, "definition name") - .required("params", SyntaxShape::Signature, "parameters") - .required("block", SyntaxShape::Block, "body of the definition") - .category(Category::Core) - } - - fn extra_usage(&self) -> &str { - r#"This command is a parser keyword. For details, check: - https://www.nushell.sh/book/thinking_in_nu.html -"# - } - - fn is_parser_keyword(&self) -> bool { - true - } - - fn run( - &self, - engine_state: &EngineState, - _stack: &mut Stack, - call: &Call, - _input: PipelineData, - ) -> Result { - nu_protocol::report_error_new( - engine_state, - &ShellError::GenericError( - "Deprecated command".into(), - "`def-env` is deprecated and will be removed in 0.88.".into(), - Some(call.head), - Some("Use `def --env` instead".into()), - vec![], - ), - ); - Ok(PipelineData::empty()) - } - - fn examples(&self) -> Vec { - vec![Example { - description: "Set environment variable by call a custom command", - example: r#"def-env foo [] { $env.BAR = "BAZ" }; foo; $env.BAR"#, - result: Some(Value::test_string("BAZ")), - }] - } -} diff --git a/crates/nu-cmd-lang/src/core_commands/export_def_env.rs b/crates/nu-cmd-lang/src/core_commands/export_def_env.rs deleted file mode 100644 index ce2aed5ca8..0000000000 --- a/crates/nu-cmd-lang/src/core_commands/export_def_env.rs +++ /dev/null @@ -1,94 +0,0 @@ -use nu_protocol::ast::Call; -use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{ - Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Type, Value, -}; - -#[derive(Clone)] -pub struct ExportDefEnv; - -impl Command for ExportDefEnv { - fn name(&self) -> &str { - "export def-env" - } - - fn usage(&self) -> &str { - "Define a custom command that participates in the environment and export it from a module." - } - - fn signature(&self) -> nu_protocol::Signature { - Signature::build("export def-env") - .input_output_types(vec![(Type::Nothing, Type::Nothing)]) - .required("name", SyntaxShape::String, "definition name") - .required("params", SyntaxShape::Signature, "parameters") - .required("block", SyntaxShape::Block, "body of the definition") - .category(Category::Core) - } - - fn extra_usage(&self) -> &str { - r#"This command is a parser keyword. For details, check: - https://www.nushell.sh/book/thinking_in_nu.html - -=== EXTRA NOTE === -All blocks are scoped, including variable definition and environment variable changes. - -Because of this, the following doesn't work: - -export def-env cd_with_fallback [arg = ""] { - let fall_back_path = "/tmp" - if $arg != "" { - cd $arg - } else { - cd $fall_back_path - } -} - -Instead, you have to use cd in the top level scope: - -export def-env cd_with_fallback [arg = ""] { - let fall_back_path = "/tmp" - let path = if $arg != "" { - $arg - } else { - $fall_back_path - } - cd $path -}"# - } - - fn is_parser_keyword(&self) -> bool { - true - } - - fn run( - &self, - engine_state: &EngineState, - _stack: &mut Stack, - call: &Call, - _input: PipelineData, - ) -> Result { - nu_protocol::report_error_new( - engine_state, - &ShellError::GenericError( - "Deprecated command".into(), - "`export def-env` is deprecated and will be removed in 0.88.".into(), - Some(call.head), - Some("Use `export def --env` instead".into()), - vec![], - ), - ); - Ok(PipelineData::empty()) - } - - fn examples(&self) -> Vec { - vec![Example { - description: "Define a custom command that participates in the environment in a module and call it", - example: r#"module foo { export def-env bar [] { $env.FOO_BAR = "BAZ" } }; use foo bar; bar; $env.FOO_BAR"#, - result: Some(Value::test_string("BAZ")), - }] - } - - fn search_terms(&self) -> Vec<&str> { - vec!["module"] - } -} diff --git a/crates/nu-cmd-lang/src/core_commands/mod.rs b/crates/nu-cmd-lang/src/core_commands/mod.rs index b6b7a227e9..627533b4b3 100644 --- a/crates/nu-cmd-lang/src/core_commands/mod.rs +++ b/crates/nu-cmd-lang/src/core_commands/mod.rs @@ -4,7 +4,6 @@ mod collect; mod const_; mod continue_; mod def; -mod def_env; mod describe; mod do_; mod echo; @@ -13,7 +12,6 @@ mod export; mod export_alias; mod export_const; mod export_def; -mod export_def_env; mod export_extern; mod export_module; mod export_use; @@ -43,7 +41,6 @@ pub use collect::Collect; pub use const_::Const; pub use continue_::Continue; pub use def::Def; -pub use def_env::DefEnv; pub use describe::Describe; pub use do_::Do; pub use echo::Echo; @@ -52,7 +49,6 @@ pub use export::ExportCommand; pub use export_alias::ExportAlias; pub use export_const::ExportConst; pub use export_def::ExportDef; -pub use export_def_env::ExportDefEnv; pub use export_extern::ExportExtern; pub use export_module::ExportModule; pub use export_use::ExportUse; diff --git a/crates/nu-cmd-lang/src/default_context.rs b/crates/nu-cmd-lang/src/default_context.rs index 35a956cb35..fd3ff95c20 100644 --- a/crates/nu-cmd-lang/src/default_context.rs +++ b/crates/nu-cmd-lang/src/default_context.rs @@ -22,7 +22,6 @@ pub fn create_default_context() -> EngineState { Const, Continue, Def, - DefEnv, Describe, Do, Echo, @@ -31,7 +30,6 @@ pub fn create_default_context() -> EngineState { ExportCommand, ExportConst, ExportDef, - ExportDefEnv, ExportExtern, ExportUse, ExportModule, diff --git a/crates/nu-cmd-lang/src/example_test.rs b/crates/nu-cmd-lang/src/example_test.rs index fa74059f90..09c01234f3 100644 --- a/crates/nu-cmd-lang/src/example_test.rs +++ b/crates/nu-cmd-lang/src/example_test.rs @@ -14,8 +14,7 @@ mod test_examples { check_example_input_and_output_types_match_command_signature, }; use crate::{ - Break, Collect, Def, DefEnv, Describe, Echo, ExportCommand, ExportDef, ExportDefEnv, If, - Let, Module, Mut, Use, + Break, Collect, Def, Describe, Echo, ExportCommand, ExportDef, If, Let, Module, Mut, Use, }; use nu_protocol::{ engine::{Command, EngineState, StateWorkingSet}, @@ -69,12 +68,10 @@ mod test_examples { working_set.add_decl(Box::new(Break)); working_set.add_decl(Box::new(Collect)); working_set.add_decl(Box::new(Def)); - working_set.add_decl(Box::new(DefEnv)); working_set.add_decl(Box::new(Describe)); working_set.add_decl(Box::new(Echo)); working_set.add_decl(Box::new(ExportCommand)); working_set.add_decl(Box::new(ExportDef)); - working_set.add_decl(Box::new(ExportDefEnv)); working_set.add_decl(Box::new(If)); working_set.add_decl(Box::new(Let)); working_set.add_decl(Box::new(Module)); diff --git a/crates/nu-parser/src/parse_keywords.rs b/crates/nu-parser/src/parse_keywords.rs index 8303e046f2..0697c90764 100644 --- a/crates/nu-parser/src/parse_keywords.rs +++ b/crates/nu-parser/src/parse_keywords.rs @@ -149,7 +149,7 @@ pub fn parse_def_predecl(working_set: &mut StateWorkingSet, spans: &[Span]) { return; }; - if def_type_name != b"def" && def_type_name != b"def-env" && def_type_name != b"extern" { + if def_type_name != b"def" && def_type_name != b"extern" { return; } @@ -372,7 +372,7 @@ pub fn parse_def( }; let def_call = working_set.get_span_contents(name_span).to_vec(); - if def_call != b"def" && def_call != b"def-env" { + if def_call != b"def" { working_set.error(ParseError::UnknownState( "internal error: Wrong call name for def function".into(), span(spans), @@ -569,7 +569,7 @@ pub fn parse_def( let calls_itself = block_calls_itself(block, decl_id); block.recursive = Some(calls_itself); block.signature = signature; - block.redirect_env = def_call == b"def-env" || has_env; + block.redirect_env = has_env; if block.signature.input_output_types.is_empty() { block @@ -1049,7 +1049,7 @@ pub fn parse_export_in_block( let full_name = if lite_command.parts.len() > 1 { let sub = working_set.get_span_contents(lite_command.parts[1]); match sub { - b"alias" | b"def" | b"def-env" | b"extern" | b"use" | b"module" | b"const" => { + b"alias" | b"def" | b"extern" | b"use" | b"module" | b"const" => { [b"export ", sub].concat() } _ => b"export".to_vec(), @@ -1108,7 +1108,7 @@ pub fn parse_export_in_block( match full_name.as_slice() { b"export alias" => parse_alias(working_set, lite_command, None), - b"export def" | b"export def-env" => parse_def(working_set, lite_command, None).0, + b"export def" => parse_def(working_set, lite_command, None).0, b"export const" => parse_const(working_set, &lite_command.parts[1..]), b"export use" => { let (pipeline, _) = parse_use(working_set, &lite_command.parts); @@ -1224,66 +1224,6 @@ pub fn parse_export_in_module( result } - b"def-env" => { - let lite_command = LiteCommand { - comments: lite_command.comments.clone(), - parts: spans[1..].to_vec(), - }; - let (pipeline, _) = parse_def(working_set, &lite_command, Some(module_name)); - - let export_def_decl_id = if let Some(id) = working_set.find_decl(b"export def-env") - { - id - } else { - working_set.error(ParseError::InternalError( - "missing 'export def-env' command".into(), - export_span, - )); - return (garbage_pipeline(spans), vec![]); - }; - - // Trying to warp the 'def' call into the 'export def' in a very clumsy way - if let Some(PipelineElement::Expression( - _, - Expression { - expr: Expr::Call(ref def_call), - .. - }, - )) = pipeline.elements.first() - { - call = def_call.clone(); - - call.head = span(&spans[0..=1]); - call.decl_id = export_def_decl_id; - } else { - working_set.error(ParseError::InternalError( - "unexpected output from parsing a definition".into(), - span(&spans[1..]), - )); - }; - - let mut result = vec![]; - - let decl_name = match spans.get(2) { - Some(span) => working_set.get_span_contents(*span), - None => &[], - }; - let decl_name = trim_quotes(decl_name); - - if let Some(decl_id) = working_set.find_decl(decl_name) { - result.push(Exportable::Decl { - name: decl_name.to_vec(), - id: decl_id, - }); - } else { - working_set.error(ParseError::InternalError( - "failed to find added declaration".into(), - span(&spans[1..]), - )); - } - - result - } b"extern" => { let lite_command = LiteCommand { comments: lite_command.comments.clone(), @@ -1563,7 +1503,7 @@ pub fn parse_export_in_module( } _ => { working_set.error(ParseError::Expected( - "def, def-env, alias, use, module, const or extern keyword", + "def, alias, use, module, const or extern keyword", spans[1], )); @@ -1572,9 +1512,9 @@ pub fn parse_export_in_module( } } else { working_set.error(ParseError::MissingPositional( - "def, def-env, alias, use, module, const or extern keyword".to_string(), + "def, alias, use, module, const or extern keyword".to_string(), Span::new(export_span.end, export_span.end), - "def, def-env, alias, use, module, const or extern keyword".to_string(), + "def, alias, use, module, const or extern keyword".to_string(), )); vec![] @@ -1743,7 +1683,7 @@ pub fn parse_module_block( let name = working_set.get_span_contents(command.parts[0]); match name { - b"def" | b"def-env" => { + b"def" => { block.pipelines.push( parse_def( working_set, @@ -1898,7 +1838,7 @@ pub fn parse_module_block( } _ => { working_set.error(ParseError::ExpectedKeyword( - "def, const, def-env, extern, alias, use, module, export or export-env keyword".into(), + "def, const, extern, alias, use, module, export or export-env keyword".into(), command.parts[0], )); diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index 5fb1e7c9c6..c478729fd4 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -5085,7 +5085,7 @@ pub fn parse_builtin_commands( let name = working_set.get_span_contents(lite_command.parts[0]); match name { - b"def" | b"def-env" => parse_def(working_set, lite_command, None).0, + b"def" => parse_def(working_set, lite_command, None).0, b"extern" => parse_extern(working_set, lite_command, None), b"let" => parse_let(working_set, &lite_command.parts), b"const" => parse_const(working_set, &lite_command.parts),