forked from extern/nushell
Add examples for env,let-env,rm,touch and date list-timezone (#4531)
* feat: update #4518, add examples for env,let-env,rm,touch and date list-timezone * fix typo * update example for `date list-timezone` command
This commit is contained in:
parent
dd11be03be
commit
1235d516a5
@ -1,7 +1,9 @@
|
||||
use chrono_tz::TZ_VARIANTS;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{Category, IntoInterruptiblePipelineData, PipelineData, Signature, Value};
|
||||
use nu_protocol::{
|
||||
Category, Example, IntoInterruptiblePipelineData, PipelineData, Signature, Span, Value,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SubCommand;
|
||||
@ -41,4 +43,19 @@ impl Command for SubCommand {
|
||||
.into_iter()
|
||||
.into_pipeline_data(engine_state.ctrlc.clone()))
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
example: "date list-timezone | where timezone =~ Shanghai",
|
||||
description: "Show timezone(s) that contains 'Shanghai'",
|
||||
result: Some(Value::List {
|
||||
vals: vec![Value::Record {
|
||||
cols: vec!["timezone".into()],
|
||||
vals: vec![Value::test_string("Asia/Shanghai")],
|
||||
span: Span::test_data(),
|
||||
}],
|
||||
span: Span::test_data(),
|
||||
}),
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
22
crates/nu-command/src/env/env_command.rs
vendored
22
crates/nu-command/src/env/env_command.rs
vendored
@ -1,7 +1,7 @@
|
||||
use nu_engine::env_to_string;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{Category, IntoPipelineData, PipelineData, Signature, Value};
|
||||
use nu_protocol::{Category, Example, IntoPipelineData, PipelineData, Signature, Value};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Env;
|
||||
@ -59,4 +59,24 @@ impl Command for Env {
|
||||
|
||||
Ok(Value::List { vals: values, span }.into_pipeline_data())
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![
|
||||
Example {
|
||||
description: "Display current path environment variable",
|
||||
example: "env | where name == PATH",
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Check whether the env variable `MY_ENV_ABC` exists",
|
||||
example: r#"env | any? name == MY_ENV_ABC"#,
|
||||
result: Some(Value::test_bool(false)),
|
||||
},
|
||||
Example {
|
||||
description: "Another way to check whether the env variable `PATH` exists",
|
||||
example: r#"'PATH' in (env).name"#,
|
||||
result: Some(Value::test_bool(true)),
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
10
crates/nu-command/src/env/let_env.rs
vendored
10
crates/nu-command/src/env/let_env.rs
vendored
@ -1,7 +1,7 @@
|
||||
use nu_engine::{current_dir, eval_expression_with_input, CallExt};
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{Category, PipelineData, Signature, SyntaxShape, Value};
|
||||
use nu_protocol::{Category, Example, PipelineData, Signature, SyntaxShape, Value};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct LetEnv;
|
||||
@ -58,4 +58,12 @@ impl Command for LetEnv {
|
||||
}
|
||||
Ok(PipelineData::new(call.head))
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![Example {
|
||||
description: "Create an environment variable and display it",
|
||||
example: "let-env MY_ENV_VAR = 1; $env.MY_ENV_VAR",
|
||||
result: Some(Value::test_int(1)),
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,8 @@ use nu_engine::CallExt;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{
|
||||
Category, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span, Spanned,
|
||||
SyntaxShape, Type, Value,
|
||||
Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, Span,
|
||||
Spanned, SyntaxShape, Type, Value,
|
||||
};
|
||||
|
||||
const GLOB_PARAMS: glob::MatchOptions = glob::MatchOptions {
|
||||
@ -67,6 +67,31 @@ impl Command for Rm {
|
||||
) -> Result<PipelineData, ShellError> {
|
||||
rm(engine_state, stack, call)
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![
|
||||
Example {
|
||||
description: "Delete or move a file to the system trash (depending on 'rm_always_trash' config option)",
|
||||
example: "rm file.txt",
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Move a file to the system trash",
|
||||
example: "rm --trash file.txt",
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Delete a file permanently",
|
||||
example: "rm --permanent file.txt",
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Delete a file, and suppress errors if no file is found",
|
||||
example: "rm --force file.txt",
|
||||
result: None,
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
fn rm(
|
||||
|
@ -3,7 +3,7 @@ use std::fs::OpenOptions;
|
||||
use nu_engine::CallExt;
|
||||
use nu_protocol::ast::Call;
|
||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||
use nu_protocol::{Category, PipelineData, ShellError, Signature, SyntaxShape};
|
||||
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, SyntaxShape};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Touch;
|
||||
@ -52,4 +52,19 @@ impl Command for Touch {
|
||||
|
||||
Ok(PipelineData::new(call.head))
|
||||
}
|
||||
|
||||
fn examples(&self) -> Vec<Example> {
|
||||
vec![
|
||||
Example {
|
||||
description: "Creates \"fixture.json\"",
|
||||
example: "touch fixture.json",
|
||||
result: None,
|
||||
},
|
||||
Example {
|
||||
description: "Creates files a, b and c",
|
||||
example: "touch a b c",
|
||||
result: None,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user