rename set/set-env to let/let-env (#2859)

This commit is contained in:
Jonathan Turner
2021-01-05 12:30:55 +13:00
committed by GitHub
parent b9bb4692a4
commit 17a433996e
7 changed files with 37 additions and 37 deletions

View File

@ -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

View File

@ -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()]),
},
]

View File

@ -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 {

View File

@ -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 {