diff --git a/crates/nu-command/src/core_commands/alias.rs b/crates/nu-command/src/core_commands/alias.rs index 158a3e9de6..b0a9adb161 100644 --- a/crates/nu-command/src/core_commands/alias.rs +++ b/crates/nu-command/src/core_commands/alias.rs @@ -1,6 +1,6 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Category, PipelineData, Signature, SyntaxShape}; +use nu_protocol::{Category, Example, PipelineData, Signature, SyntaxShape}; #[derive(Clone)] pub struct Alias; @@ -34,4 +34,12 @@ impl Command for Alias { ) -> Result { Ok(PipelineData::new(call.head)) } + + fn examples(&self) -> Vec { + vec![Example { + description: "Alias ll to ls -l", + example: "alias ll = ls -l", + result: None, + }] + } } diff --git a/crates/nu-command/src/core_commands/let_.rs b/crates/nu-command/src/core_commands/let_.rs index 9c90c60783..beb7716c41 100644 --- a/crates/nu-command/src/core_commands/let_.rs +++ b/crates/nu-command/src/core_commands/let_.rs @@ -61,6 +61,11 @@ impl Command for Let { example: "let x = 10 + 100", result: None, }, + Example { + description: "Set a variable based on the condition", + example: "let x = if $false { -1 } else { 1 }", + result: None, + }, ] } } diff --git a/crates/nu-command/src/date/now.rs b/crates/nu-command/src/date/now.rs index 4069938338..cc5f92325d 100644 --- a/crates/nu-command/src/date/now.rs +++ b/crates/nu-command/src/date/now.rs @@ -1,7 +1,7 @@ use chrono::Local; 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 SubCommand; @@ -33,4 +33,12 @@ impl Command for SubCommand { } .into_pipeline_data()) } + + fn examples(&self) -> Vec { + 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, + }] + } } diff --git a/crates/nu-command/src/filters/update.rs b/crates/nu-command/src/filters/update.rs index 9b01be148a..f0a1f8d0bc 100644 --- a/crates/nu-command/src/filters/update.rs +++ b/crates/nu-command/src/filters/update.rs @@ -48,6 +48,10 @@ impl Command for Update { description: "Update a column value", 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()}), + }, 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 { 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 ',' }", diff --git a/crates/nu-command/src/filters/where_.rs b/crates/nu-command/src/filters/where_.rs index 99d587f124..f17943c332 100644 --- a/crates/nu-command/src/filters/where_.rs +++ b/crates/nu-command/src/filters/where_.rs @@ -1,7 +1,7 @@ use nu_engine::{eval_block_with_redirect, CallExt}; use nu_protocol::ast::Call; 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)] pub struct Where; @@ -63,4 +63,29 @@ impl Command for Where { ) .map(|x| x.set_metadata(metadata)) } + + fn examples(&self) -> Vec { + 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, + }, + ] + } } diff --git a/crates/nu-command/src/filters/wrap.rs b/crates/nu-command/src/filters/wrap.rs index 6b3667e98b..dae73e239f 100644 --- a/crates/nu-command/src/filters/wrap.rs +++ b/crates/nu-command/src/filters/wrap.rs @@ -2,8 +2,8 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; use nu_protocol::{ - Category, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature, - SyntaxShape, Value, + Category, Example, IntoInterruptiblePipelineData, IntoPipelineData, PipelineData, Signature, + Span, SyntaxShape, Value, }; #[derive(Clone)] @@ -64,4 +64,19 @@ impl Command for Wrap { .into_pipeline_data()), } } + + fn examples(&self) -> Vec { + 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(), + }), + }] + } } diff --git a/crates/nu-command/src/shells/exit.rs b/crates/nu-command/src/shells/exit.rs index 30ecf006da..7ecb03dba1 100644 --- a/crates/nu-command/src/shells/exit.rs +++ b/crates/nu-command/src/shells/exit.rs @@ -1,7 +1,7 @@ use nu_engine::{current_dir, CallExt}; use nu_protocol::ast::Call; 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. #[derive(Clone)] @@ -97,4 +97,19 @@ impl Command for Exit { Ok(PipelineData::new(call.head)) } } + + fn examples(&self) -> Vec { + vec![ + Example { + description: "Exit the current shell", + example: "exit", + result: None, + }, + Example { + description: "Exit all shells (exiting Nu)", + example: "exit --now", + result: None, + }, + ] + } } diff --git a/crates/nu-command/tests/format_conversions/html.rs b/crates/nu-command/tests/format_conversions/html.rs index 72d418ab86..e7857e9c6f 100644 --- a/crates/nu-command/tests/format_conversions/html.rs +++ b/crates/nu-command/tests/format_conversions/html.rs @@ -76,16 +76,16 @@ fn test_no_color_flag() { } #[test] -fn test_html_color_where_flag_dark_false() { +fn test_html_color_cd_flag_dark_false() { let actual = nu!( cwd: ".", pipeline( r#" - where --help | to html --html-color + cd --help | to html --html-color "# ) ); assert_eq!( actual.out, - r"Filter values based on a condition.

Usage:
> where <cond>

Flags:
-h, --help
Display this help message

Parameters:
cond: condition

" + r"Change directory.

Usage:
> cd (path)

Flags:
-h, --help
Display this help message

Parameters:
(optional) path: the path to change to

" ); }