diff --git a/crates/nu-cli/src/commands.rs b/crates/nu-cli/src/commands.rs index 7172a146e1..e3b04ec90a 100644 --- a/crates/nu-cli/src/commands.rs +++ b/crates/nu-cli/src/commands.rs @@ -73,6 +73,8 @@ pub(crate) mod insert; pub(crate) mod into_int; pub(crate) mod keep; pub(crate) mod last; +pub(crate) mod let_; +pub(crate) mod let_env; pub(crate) mod lines; pub(crate) mod ls; pub(crate) mod math; @@ -101,8 +103,6 @@ pub(crate) mod save; pub(crate) mod select; pub(crate) mod seq; pub(crate) mod seq_dates; -pub(crate) mod set; -pub(crate) mod set_env; pub(crate) mod shells; pub(crate) mod shuffle; pub(crate) mod size; @@ -212,6 +212,8 @@ pub(crate) use insert::Command as Insert; pub(crate) use into_int::IntoInt; pub(crate) use keep::{Keep, KeepUntil, KeepWhile}; pub(crate) use last::Last; +pub(crate) use let_::Let; +pub(crate) use let_env::LetEnv; pub(crate) use lines::Lines; pub(crate) use ls::Ls; pub(crate) use math::{ @@ -249,8 +251,6 @@ pub(crate) use save::Save; pub(crate) use select::Select; pub(crate) use seq::Seq; pub(crate) use seq_dates::SeqDates; -pub(crate) use set::Set; -pub(crate) use set_env::SetEnv; pub(crate) use shells::Shells; pub(crate) use shuffle::Shuffle; pub(crate) use size::Size; diff --git a/crates/nu-cli/src/commands/default_context.rs b/crates/nu-cli/src/commands/default_context.rs index c04425bb45..71ca5bf218 100644 --- a/crates/nu-cli/src/commands/default_context.rs +++ b/crates/nu-cli/src/commands/default_context.rs @@ -10,8 +10,8 @@ pub fn create_default_context(interactive: bool) -> Result 5 { echo 'greater than 5' } { echo 'less than or equal to 5' }", + example: "let x = 10; if $x > 5 { echo 'greater than 5' } { echo 'less than or equal to 5' }", result: Some(vec![UntaggedValue::string("greater than 5").into()]), }, Example { description: "Run a block if a condition is false", - example: "set x = 1; if $x > 5 { echo 'greater than 5' } { echo 'less than or equal to 5' }", + example: "let x = 1; if $x > 5 { echo 'greater than 5' } { echo 'less than or equal to 5' }", result: Some(vec![UntaggedValue::string("less than or equal to 5").into()]), }, ] diff --git a/crates/nu-cli/src/commands/set.rs b/crates/nu-cli/src/commands/let_.rs similarity index 86% rename from crates/nu-cli/src/commands/set.rs rename to crates/nu-cli/src/commands/let_.rs index 534b5fc944..b7a04f1da3 100644 --- a/crates/nu-cli/src/commands/set.rs +++ b/crates/nu-cli/src/commands/let_.rs @@ -5,38 +5,38 @@ use nu_errors::ShellError; use nu_protocol::{hir::CapturedBlock, hir::ClassifiedCommand, Signature, SyntaxShape}; use nu_source::Tagged; -pub struct Set; +pub struct Let; #[derive(Deserialize)] -pub struct SetArgs { +pub struct LetArgs { pub name: Tagged, pub equals: Tagged, pub rhs: CapturedBlock, } #[async_trait] -impl WholeStreamCommand for Set { +impl WholeStreamCommand for Let { fn name(&self) -> &str { - "set" + "let" } fn signature(&self) -> Signature { - Signature::build("set") + Signature::build("let") .required("name", SyntaxShape::String, "the name of the variable") .required("equals", SyntaxShape::String, "the equals sign") .required( "expr", SyntaxShape::MathExpression, - "the value to set the variable to", + "the value for the variable", ) } fn usage(&self) -> &str { - "Create a variable and set it to a value." + "Create a variable and give it a value." } async fn run(&self, args: CommandArgs) -> Result { - set(args).await + letcmd(args).await } fn examples(&self) -> Vec { @@ -44,11 +44,11 @@ impl WholeStreamCommand for Set { } } -pub async fn set(args: CommandArgs) -> Result { +pub async fn letcmd(args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); let ctx = EvaluationContext::from_args(&args); - let (SetArgs { name, rhs, .. }, _) = args.process().await?; + let (LetArgs { name, rhs, .. }, _) = args.process().await?; let (expr, captured) = { if rhs.block.block.len() != 1 { diff --git a/crates/nu-cli/src/commands/set_env.rs b/crates/nu-cli/src/commands/let_env.rs similarity index 88% rename from crates/nu-cli/src/commands/set_env.rs rename to crates/nu-cli/src/commands/let_env.rs index 56c7bd15b7..a7f118f939 100644 --- a/crates/nu-cli/src/commands/set_env.rs +++ b/crates/nu-cli/src/commands/let_env.rs @@ -5,23 +5,23 @@ use nu_errors::ShellError; use nu_protocol::{hir::CapturedBlock, hir::ClassifiedCommand, Signature, SyntaxShape}; use nu_source::Tagged; -pub struct SetEnv; +pub struct LetEnv; #[derive(Deserialize)] -pub struct SetEnvArgs { +pub struct LetEnvArgs { pub name: Tagged, pub equals: Tagged, pub rhs: CapturedBlock, } #[async_trait] -impl WholeStreamCommand for SetEnv { +impl WholeStreamCommand for LetEnv { fn name(&self) -> &str { - "set-env" + "let-env" } fn signature(&self) -> Signature { - Signature::build("set-env") + Signature::build("let-env") .required( "name", SyntaxShape::String, @@ -31,12 +31,12 @@ impl WholeStreamCommand for SetEnv { .required( "expr", SyntaxShape::MathExpression, - "the value to set the environment variable to", + "the value for the environment variable", ) } fn usage(&self) -> &str { - "Create an environment variable and set it to a value." + "Create an environment variable and give it a value." } async fn run(&self, args: CommandArgs) -> Result { @@ -52,7 +52,7 @@ pub async fn set_env(args: CommandArgs) -> Result { let tag = args.call_info.name_tag.clone(); let ctx = EvaluationContext::from_args(&args); - let (SetEnvArgs { name, rhs, .. }, _) = args.process().await?; + let (LetEnvArgs { name, rhs, .. }, _) = args.process().await?; let (expr, captured) = { if rhs.block.block.len() != 1 { diff --git a/crates/nu-cli/src/examples.rs b/crates/nu-cli/src/examples.rs index bf0f72b475..c691d63a44 100644 --- a/crates/nu-cli/src/examples.rs +++ b/crates/nu-cli/src/examples.rs @@ -13,7 +13,7 @@ use num_bigint::BigInt; use crate::commands::classified::block::run_block; use crate::commands::command::CommandArgs; use crate::commands::{ - whole_stream_command, BuildString, Command, Each, Echo, First, Get, Keep, Last, Nth, Set, + whole_stream_command, BuildString, Command, Each, Echo, First, Get, Keep, Last, Let, Nth, StrCollect, WholeStreamCommand, Wrap, }; use crate::evaluation_context::EvaluationContext; @@ -40,7 +40,7 @@ pub fn test_examples(cmd: Command) -> Result<(), ShellError> { whole_stream_command(Each {}), whole_stream_command(Last {}), whole_stream_command(Nth {}), - whole_stream_command(Set {}), + whole_stream_command(Let {}), whole_stream_command(StrCollect), whole_stream_command(Wrap), cmd, @@ -98,7 +98,7 @@ pub fn test(cmd: impl WholeStreamCommand + 'static) -> Result<(), ShellError> { whole_stream_command(Get {}), whole_stream_command(Keep {}), whole_stream_command(Each {}), - whole_stream_command(Set {}), + whole_stream_command(Let {}), whole_stream_command(cmd), whole_stream_command(StrCollect), whole_stream_command(Wrap), @@ -160,7 +160,7 @@ pub fn test_anchors(cmd: Command) -> Result<(), ShellError> { whole_stream_command(Each {}), whole_stream_command(Last {}), whole_stream_command(Nth {}), - whole_stream_command(Set {}), + whole_stream_command(Let {}), whole_stream_command(StrCollect), whole_stream_command(Wrap), cmd, diff --git a/tests/shell/pipeline/commands/internal.rs b/tests/shell/pipeline/commands/internal.rs index bfc4d366bc..46c43e4ce4 100644 --- a/tests/shell/pipeline/commands/internal.rs +++ b/tests/shell/pipeline/commands/internal.rs @@ -409,8 +409,8 @@ fn set_variable() { let actual = nu!( cwd: ".", r#" - set x = 5 - set y = 12 + let x = 5 + let y = 12 = $x + $y "# ); @@ -423,7 +423,7 @@ fn set_doesnt_leak() { let actual = nu!( cwd: ".", r#" - do { set x = 5 }; echo $x + do { let x = 5 }; echo $x "# ); @@ -435,7 +435,7 @@ fn set_env_variable() { let actual = nu!( cwd: ".", r#" - set-env TESTENVVAR = "hello world" + let-env TESTENVVAR = "hello world" echo $nu.env.TESTENVVAR "# ); @@ -448,7 +448,7 @@ fn set_env_doesnt_leak() { let actual = nu!( cwd: ".", r#" - do { set-env xyz = "my message" }; echo $nu.env.xyz + do { let-env xyz = "my message" }; echo $nu.env.xyz "# ); @@ -460,7 +460,7 @@ fn proper_shadow_set_env_aliases() { let actual = nu!( cwd: ".", r#" - set-env DEBUG = true; echo $nu.env.DEBUG | autoview; do { set-env DEBUG = false; echo $nu.env.DEBUG } | autoview; echo $nu.env.DEBUG + let-env DEBUG = true; echo $nu.env.DEBUG | autoview; do { let-env DEBUG = false; echo $nu.env.DEBUG } | autoview; echo $nu.env.DEBUG "# ); assert_eq!(actual.out, "truefalsetrue"); @@ -471,7 +471,7 @@ fn proper_shadow_set_aliases() { let actual = nu!( cwd: ".", r#" - set DEBUG = false; echo $DEBUG | autoview; do { set DEBUG = true; echo $DEBUG } | autoview; echo $DEBUG + let DEBUG = false; echo $DEBUG | autoview; do { let DEBUG = true; echo $DEBUG } | autoview; echo $DEBUG "# ); assert_eq!(actual.out, "falsetruefalse");