diff --git a/crates/nu-command/src/core_commands/register.rs b/crates/nu-command/src/core_commands/register.rs index ffa6f9d76..22015b217 100644 --- a/crates/nu-command/src/core_commands/register.rs +++ b/crates/nu-command/src/core_commands/register.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 Register; @@ -50,4 +50,19 @@ impl Command for Register { ) -> Result { Ok(PipelineData::new(call.head)) } + + fn examples(&self) -> Vec { + vec![ + Example { + description: "Register `nu_plugin_extra_query` plugin from ~/.cargo/bin/ dir", + example: r#"register -e capnp ~/.cargo/bin/nu_plugin_extra_query"#, + result: None, + }, + Example { + description: "Register `nu_plugin_extra_query` plugin from `nu -c`(plugin will be available in that nu session only)", + example: r#"let plugin = ((which nu).path.0 | path dirname | path join 'nu_plugin_extra_query'); nu -c $'register -e capnp ($plugin); version'"#, + result: None, + }, + ] + } } diff --git a/crates/nu-command/src/core_commands/source.rs b/crates/nu-command/src/core_commands/source.rs index b4626e5e3..17d1e427b 100644 --- a/crates/nu-command/src/core_commands/source.rs +++ b/crates/nu-command/src/core_commands/source.rs @@ -1,7 +1,7 @@ use nu_engine::{eval_block, 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}; /// Source a file for environment variables. #[derive(Clone)] @@ -40,4 +40,24 @@ impl Command for Source { let block = engine_state.get_block(block_id as usize).clone(); eval_block(engine_state, stack, &block, input) } + + fn examples(&self) -> Vec { + vec![ + Example { + description: "Runs foo.nu in the current context", + example: r#"source foo.nu"#, + result: None, + }, + Example { + description: "Runs foo.nu in current context and call the command defined, suppose foo.nu has content: `def say-hi [] { echo 'Hi!' }`", + example: r#"source ./foo.nu; say-hi"#, + result: None, + }, + Example { + description: "Runs foo.nu in current context and call the `main` command automatically, suppose foo.nu has content: `def main [] { echo 'Hi!' }`", + example: r#"source ./foo.nu"#, + result: None, + }, + ] + } } diff --git a/crates/nu-command/src/filesystem/save.rs b/crates/nu-command/src/filesystem/save.rs index 1f6b5a192..c477338f0 100644 --- a/crates/nu-command/src/filesystem/save.rs +++ b/crates/nu-command/src/filesystem/save.rs @@ -1,7 +1,9 @@ use nu_engine::CallExt; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Category, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Value}; +use nu_protocol::{ + Category, Example, PipelineData, ShellError, Signature, Spanned, SyntaxShape, Value, +}; use std::io::Write; use std::path::Path; @@ -21,7 +23,7 @@ impl Command for Save { fn signature(&self) -> nu_protocol::Signature { Signature::build("save") .required("filename", SyntaxShape::Filepath, "the filename to use") - .switch("raw", "open file as raw binary", Some('r')) + .switch("raw", "save file as raw binary", Some('r')) .category(Category::FileSystem) } @@ -115,4 +117,19 @@ impl Command for Save { } } } + + fn examples(&self) -> Vec { + vec![ + Example { + description: "Save a string to foo.txt in current directory", + example: r#"echo 'save me' | save foo.txt"#, + result: None, + }, + Example { + description: "Save a record to foo.json in current directory", + example: r#"echo { a: 1, b: 2 } | save foo.json"#, + result: None, + }, + ] + } } diff --git a/crates/nu-command/src/filters/shuffle.rs b/crates/nu-command/src/filters/shuffle.rs index 4c3f07991..89a4209bd 100644 --- a/crates/nu-command/src/filters/shuffle.rs +++ b/crates/nu-command/src/filters/shuffle.rs @@ -1,6 +1,8 @@ use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Category, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature}; +use nu_protocol::{ + Category, Example, IntoInterruptiblePipelineData, PipelineData, ShellError, Signature, +}; use rand::prelude::SliceRandom; use rand::thread_rng; @@ -32,4 +34,13 @@ impl Command for Shuffle { let iter = v.into_iter(); Ok(iter.into_pipeline_data(engine_state.ctrlc.clone())) } + + fn examples(&self) -> Vec { + vec![Example { + description: + "Shuffle rows randomly(execute it a few more times and see the difference)", + example: r#"echo [[version patch]; [1.0.0 $false] [3.0.1 $true] [2.0.0 $false]] | shuffle"#, + result: None, + }] + } } diff --git a/crates/nu-command/src/formats/from/tsv.rs b/crates/nu-command/src/formats/from/tsv.rs index 991c58a31..a38346dd0 100644 --- a/crates/nu-command/src/formats/from/tsv.rs +++ b/crates/nu-command/src/formats/from/tsv.rs @@ -2,7 +2,7 @@ use super::delimited::from_delimited_data; use nu_protocol::ast::Call; use nu_protocol::engine::{Command, EngineState, Stack}; -use nu_protocol::{Category, Config, PipelineData, ShellError, Signature}; +use nu_protocol::{Category, Config, Example, PipelineData, ShellError, Signature}; #[derive(Clone)] pub struct FromTsv; @@ -36,6 +36,21 @@ impl Command for FromTsv { let config = stack.get_config().unwrap_or_default(); from_tsv(call, input, &config) } + + fn examples(&self) -> Vec { + vec![ + Example { + description: "Create a tsv file with header columns and open it", + example: r#"echo $'c1(char tab)c2(char tab)c3(char nl)1(char tab)2(char tab)3' | save tsv-data | open tsv-data | from tsv"#, + result: None, + }, + Example { + description: "Create a tsv file without header columns and open it", + example: r#"echo $'a1(char tab)b1(char tab)c1(char nl)a2(char tab)b2(char tab)c2' | save tsv-data | open tsv-data | from tsv -n"#, + result: None, + }, + ] + } } fn from_tsv(call: &Call, input: PipelineData, config: &Config) -> Result {