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:
Justin Ma
2022-02-19 00:19:37 +08:00
committed by GitHub
parent dd11be03be
commit 1235d516a5
5 changed files with 91 additions and 6 deletions

View File

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

View File

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