mirror of
https://github.com/nushell/nushell
synced 2024-11-13 00:17:06 +00:00
Add or update examples for some commands (#4521)
* chore: add or update examples for some commands * chore: code formatting
This commit is contained in:
parent
1377693f0f
commit
a5f9ad2a43
8 changed files with 89 additions and 9 deletions
|
@ -1,6 +1,6 @@
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||||
use nu_protocol::{Category, PipelineData, Signature, SyntaxShape};
|
use nu_protocol::{Category, Example, PipelineData, Signature, SyntaxShape};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Alias;
|
pub struct Alias;
|
||||||
|
@ -34,4 +34,12 @@ impl Command for Alias {
|
||||||
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
) -> Result<nu_protocol::PipelineData, nu_protocol::ShellError> {
|
||||||
Ok(PipelineData::new(call.head))
|
Ok(PipelineData::new(call.head))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
vec![Example {
|
||||||
|
description: "Alias ll to ls -l",
|
||||||
|
example: "alias ll = ls -l",
|
||||||
|
result: None,
|
||||||
|
}]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,6 +61,11 @@ impl Command for Let {
|
||||||
example: "let x = 10 + 100",
|
example: "let x = 10 + 100",
|
||||||
result: None,
|
result: None,
|
||||||
},
|
},
|
||||||
|
Example {
|
||||||
|
description: "Set a variable based on the condition",
|
||||||
|
example: "let x = if $false { -1 } else { 1 }",
|
||||||
|
result: None,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use chrono::Local;
|
use chrono::Local;
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
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)]
|
#[derive(Clone)]
|
||||||
pub struct SubCommand;
|
pub struct SubCommand;
|
||||||
|
|
||||||
|
@ -33,4 +33,12 @@ impl Command for SubCommand {
|
||||||
}
|
}
|
||||||
.into_pipeline_data())
|
.into_pipeline_data())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
vec![Example {
|
||||||
|
description: "Get the current date and display it in a given format string.",
|
||||||
|
example: r#"date now | date format "%Y-%m-%d %H:%M:%S""#,
|
||||||
|
result: None,
|
||||||
|
}]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,10 @@ impl Command for Update {
|
||||||
description: "Update a column value",
|
description: "Update a column value",
|
||||||
example: "echo {'name': 'nu', 'stars': 5} | update name 'Nushell'",
|
example: "echo {'name': 'nu', 'stars': 5} | update name 'Nushell'",
|
||||||
result: Some(Value::Record { cols: vec!["name".into(), "stars".into()], vals: vec![Value::test_string("Nushell"), Value::test_int(5)], span: Span::test_data()}),
|
result: Some(Value::Record { cols: vec!["name".into(), "stars".into()], vals: vec![Value::test_string("Nushell"), Value::test_int(5)], span: Span::test_data()}),
|
||||||
|
}, Example {
|
||||||
|
description: "Use in block form for more involved updating logic",
|
||||||
|
example: "echo [[count fruit]; [1 'apple']] | update count {|f| $f.count + 1}",
|
||||||
|
result: Some(Value::List { vals: vec![Value::Record { cols: vec!["count".into(), "fruit".into()], vals: vec![Value::test_int(2), Value::test_string("apple")], span: Span::test_data()}], span: Span::test_data()}),
|
||||||
}, Example {
|
}, Example {
|
||||||
description: "Use in block form for more involved updating logic",
|
description: "Use in block form for more involved updating logic",
|
||||||
example: "echo [[project, authors]; ['nu', ['Andrés', 'JT', 'Yehuda']]] | update authors { get authors | str collect ',' }",
|
example: "echo [[project, authors]; ['nu', ['Andrés', 'JT', 'Yehuda']]] | update authors { get authors | str collect ',' }",
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use nu_engine::{eval_block_with_redirect, CallExt};
|
use nu_engine::{eval_block_with_redirect, CallExt};
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{CaptureBlock, Command, EngineState, Stack};
|
use nu_protocol::engine::{CaptureBlock, Command, EngineState, Stack};
|
||||||
use nu_protocol::{Category, PipelineData, Signature, SyntaxShape};
|
use nu_protocol::{Category, Example, PipelineData, Signature, SyntaxShape};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Where;
|
pub struct Where;
|
||||||
|
@ -63,4 +63,29 @@ impl Command for Where {
|
||||||
)
|
)
|
||||||
.map(|x| x.set_metadata(metadata))
|
.map(|x| x.set_metadata(metadata))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
vec![
|
||||||
|
Example {
|
||||||
|
description: "List all files in the current directory with sizes greater than 2kb",
|
||||||
|
example: "ls | where size > 2kb",
|
||||||
|
result: None,
|
||||||
|
},
|
||||||
|
Example {
|
||||||
|
description: "List only the files in the current directory",
|
||||||
|
example: "ls | where type == file",
|
||||||
|
result: None,
|
||||||
|
},
|
||||||
|
Example {
|
||||||
|
description: "List all files with names that contain \"Car\"",
|
||||||
|
example: "ls | where name =~ \"Car\"",
|
||||||
|
result: None,
|
||||||
|
},
|
||||||
|
Example {
|
||||||
|
description: "List all files that were modified in the last two weeks",
|
||||||
|
example: "ls | where modified <= 2wk",
|
||||||
|
result: None,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@ use nu_engine::CallExt;
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||||
use nu_protocol::{
|
use nu_protocol::{
|
||||||
Category, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature,
|
Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature,
|
||||||
SyntaxShape, Value,
|
Span, SyntaxShape, Value,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -64,4 +64,19 @@ impl Command for Wrap {
|
||||||
.into_pipeline_data()),
|
.into_pipeline_data()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
vec![Example {
|
||||||
|
description: "Wrap a list into a table with a given column name",
|
||||||
|
example: "echo [1 2 3] | wrap num",
|
||||||
|
result: Some(Value::List {
|
||||||
|
vals: vec![Value::Record {
|
||||||
|
cols: vec!["num".into()],
|
||||||
|
vals: vec![Value::test_int(1), Value::test_int(2), Value::test_int(3)],
|
||||||
|
span: Span::test_data(),
|
||||||
|
}],
|
||||||
|
span: Span::test_data(),
|
||||||
|
}),
|
||||||
|
}]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use nu_engine::{current_dir, CallExt};
|
use nu_engine::{current_dir, CallExt};
|
||||||
use nu_protocol::ast::Call;
|
use nu_protocol::ast::Call;
|
||||||
use nu_protocol::engine::{Command, EngineState, Stack};
|
use nu_protocol::engine::{Command, EngineState, Stack};
|
||||||
use nu_protocol::{Category, PipelineData, ShellError, Signature, SyntaxShape, Value};
|
use nu_protocol::{Category, Example, PipelineData, ShellError, Signature, SyntaxShape, Value};
|
||||||
|
|
||||||
/// Source a file for environment variables.
|
/// Source a file for environment variables.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -97,4 +97,19 @@ impl Command for Exit {
|
||||||
Ok(PipelineData::new(call.head))
|
Ok(PipelineData::new(call.head))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn examples(&self) -> Vec<Example> {
|
||||||
|
vec![
|
||||||
|
Example {
|
||||||
|
description: "Exit the current shell",
|
||||||
|
example: "exit",
|
||||||
|
result: None,
|
||||||
|
},
|
||||||
|
Example {
|
||||||
|
description: "Exit all shells (exiting Nu)",
|
||||||
|
example: "exit --now",
|
||||||
|
result: None,
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,16 +76,16 @@ fn test_no_color_flag() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_html_color_where_flag_dark_false() {
|
fn test_html_color_cd_flag_dark_false() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".", pipeline(
|
cwd: ".", pipeline(
|
||||||
r#"
|
r#"
|
||||||
where --help | to html --html-color
|
cd --help | to html --html-color
|
||||||
"#
|
"#
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
actual.out,
|
actual.out,
|
||||||
r"<html><style>body { background-color:white;color:black; }</style><body>Filter values based on a condition.<br><br>Usage:<br> > where <cond> <br><br>Flags:<br> -h, --help<br> Display this help message<br><br>Parameters:<br> cond: condition<br><br></body></html>"
|
r"<html><style>body { background-color:white;color:black; }</style><body>Change directory.<br><br>Usage:<br> > cd (path) <br><br>Flags:<br> -h, --help<br> Display this help message<br><br>Parameters:<br> (optional) path: the path to change to<br><br></body></html>"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue