mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
rename set/set-env to let/let-env (#2859)
This commit is contained in:
parent
b9bb4692a4
commit
17a433996e
7 changed files with 37 additions and 37 deletions
|
@ -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;
|
||||
|
|
|
@ -10,8 +10,8 @@ pub fn create_default_context(interactive: bool) -> Result<EvaluationContext, Bo
|
|||
context.add_commands(vec![
|
||||
// Fundamentals
|
||||
whole_stream_command(NuPlugin),
|
||||
whole_stream_command(Set),
|
||||
whole_stream_command(SetEnv),
|
||||
whole_stream_command(Let),
|
||||
whole_stream_command(LetEnv),
|
||||
whole_stream_command(Def),
|
||||
whole_stream_command(Source),
|
||||
// System/file operations
|
||||
|
|
|
@ -53,12 +53,12 @@ impl WholeStreamCommand for If {
|
|||
vec![
|
||||
Example {
|
||||
description: "Run a block if a condition is true",
|
||||
example: "set x = 10; if $x > 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()]),
|
||||
},
|
||||
]
|
||||
|
|
|
@ -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<String>,
|
||||
pub equals: Tagged<String>,
|
||||
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<OutputStream, ShellError> {
|
||||
set(args).await
|
||||
letcmd(args).await
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
|
@ -44,11 +44,11 @@ impl WholeStreamCommand for Set {
|
|||
}
|
||||
}
|
||||
|
||||
pub async fn set(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
pub async fn letcmd(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
||||
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 {
|
|
@ -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<String>,
|
||||
pub equals: Tagged<String>,
|
||||
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<OutputStream, ShellError> {
|
||||
|
@ -52,7 +52,7 @@ pub async fn set_env(args: CommandArgs) -> Result<OutputStream, ShellError> {
|
|||
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 {
|
|
@ -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,
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in a new issue