diff --git a/crates/nu-cli/src/commands/alias.rs b/crates/nu-cli/src/commands/alias.rs index c7ad0c97cd..8c78eac4bd 100644 --- a/crates/nu-cli/src/commands/alias.rs +++ b/crates/nu-cli/src/commands/alias.rs @@ -1,4 +1,4 @@ -use crate::commands::{Example, WholeStreamCommand}; +use crate::commands::WholeStreamCommand; use crate::context::CommandRegistry; use crate::prelude::*; use nu_errors::ShellError; diff --git a/crates/nu-cli/src/commands/append.rs b/crates/nu-cli/src/commands/append.rs index c094d02e6c..e3b12c748f 100644 --- a/crates/nu-cli/src/commands/append.rs +++ b/crates/nu-cli/src/commands/append.rs @@ -35,6 +35,13 @@ impl WholeStreamCommand for Append { ) -> Result { args.process(registry, append)?.run() } + + fn examples(&self) -> &[Example] { + &[Example { + description: "Add something to the end of a list or table", + example: "echo [1 2 3] | append 4", + }] + } } fn append( diff --git a/crates/nu-cli/src/commands/autoview.rs b/crates/nu-cli/src/commands/autoview.rs index 976ff5c296..9b655d6862 100644 --- a/crates/nu-cli/src/commands/autoview.rs +++ b/crates/nu-cli/src/commands/autoview.rs @@ -37,6 +37,19 @@ impl WholeStreamCommand for Autoview { name: args.call_info.name_tag, }) } + + fn examples(&self) -> &[Example] { + &[ + Example { + description: "Automatically view the results", + example: "ls | autoview", + }, + Example { + description: "Autoview is also implied. The above can be written as", + example: "ls", + }, + ] + } } pub struct RunnableContextWithoutInput { diff --git a/crates/nu-cli/src/commands/cal.rs b/crates/nu-cli/src/commands/cal.rs index 6f54968c4a..3f3022aff0 100644 --- a/crates/nu-cli/src/commands/cal.rs +++ b/crates/nu-cli/src/commands/cal.rs @@ -43,6 +43,19 @@ impl WholeStreamCommand for Cal { ) -> Result { cal(args, registry) } + + fn examples(&self) -> &[Example] { + &[ + Example { + description: "This month's calendar", + example: "cal", + }, + Example { + description: "The calendar for all of 2012", + example: "cal --full-year 2012", + }, + ] + } } pub fn cal(args: CommandArgs, registry: &CommandRegistry) -> Result { diff --git a/crates/nu-cli/src/commands/calc.rs b/crates/nu-cli/src/commands/calc.rs index 2785d10ccf..0196cd55c4 100644 --- a/crates/nu-cli/src/commands/calc.rs +++ b/crates/nu-cli/src/commands/calc.rs @@ -24,6 +24,13 @@ impl WholeStreamCommand for Calc { ) -> Result { args.process(registry, calc)?.run() } + + fn examples(&self) -> &[Example] { + &[Example { + description: "Calculate math in the pipeline", + example: "echo '10 / 4' | calc", + }] + } } pub fn calc( diff --git a/crates/nu-cli/src/commands/cd.rs b/crates/nu-cli/src/commands/cd.rs index 8f766545b0..3d2a017818 100644 --- a/crates/nu-cli/src/commands/cd.rs +++ b/crates/nu-cli/src/commands/cd.rs @@ -38,6 +38,27 @@ impl WholeStreamCommand for Cd { ) -> Result { args.process(registry, cd)?.run() } + + fn examples(&self) -> &[Example] { + &[ + Example { + description: "Change to a new directory called 'dirname'", + example: "cd dirname", + }, + Example { + description: "Change to your home directory", + example: "cd", + }, + Example { + description: "Change to your home directory (alternate version)", + example: "cd ~", + }, + Example { + description: "Change to the previous directory", + example: "cd -", + }, + ] + } } fn cd(args: CdArgs, context: RunnableContext) -> Result { diff --git a/crates/nu-cli/src/commands/clear.rs b/crates/nu-cli/src/commands/clear.rs index 21590e10ac..eed4fd7663 100644 --- a/crates/nu-cli/src/commands/clear.rs +++ b/crates/nu-cli/src/commands/clear.rs @@ -23,6 +23,12 @@ impl WholeStreamCommand for Clear { ) -> Result { clear(args, registry) } + fn examples(&self) -> &[Example] { + &[Example { + description: "Clear the screen", + example: "clear", + }] + } } fn clear(_args: CommandArgs, _registry: &CommandRegistry) -> Result { if cfg!(windows) { diff --git a/crates/nu-cli/src/commands/clip.rs b/crates/nu-cli/src/commands/clip.rs index 5ab7ff79de..2fb112e153 100644 --- a/crates/nu-cli/src/commands/clip.rs +++ b/crates/nu-cli/src/commands/clip.rs @@ -34,6 +34,13 @@ pub mod clipboard { ) -> Result { args.process(registry, clip)?.run() } + + fn examples(&self) -> &[Example] { + &[Example { + description: "Save text to the clipboard", + example: "echo 'secret value' | clip", + }] + } } pub fn clip( diff --git a/crates/nu-cli/src/commands/compact.rs b/crates/nu-cli/src/commands/compact.rs index 240a6a74d6..0300c10f85 100644 --- a/crates/nu-cli/src/commands/compact.rs +++ b/crates/nu-cli/src/commands/compact.rs @@ -33,6 +33,13 @@ impl WholeStreamCommand for Compact { ) -> Result { args.process(registry, compact)?.run() } + + fn examples(&self) -> &[Example] { + &[Example { + description: "Remove all directory entries, except those with a 'target'", + example: "ls -af | compact target", + }] + } } pub fn compact( diff --git a/crates/nu-cli/src/commands/count.rs b/crates/nu-cli/src/commands/count.rs index f9f4ca48e7..5ed2b0bb82 100644 --- a/crates/nu-cli/src/commands/count.rs +++ b/crates/nu-cli/src/commands/count.rs @@ -20,7 +20,7 @@ impl WholeStreamCommand for Count { } fn usage(&self) -> &str { - "Show the total number of rows." + "Show the total number of rows or items." } fn run( @@ -30,6 +30,13 @@ impl WholeStreamCommand for Count { ) -> Result { args.process(registry, count)?.run() } + + fn examples(&self) -> &[Example] { + &[Example { + description: "Count the number of files/directories in the current directory", + example: "ls | count", + }] + } } pub fn count( diff --git a/crates/nu-cli/src/commands/prepend.rs b/crates/nu-cli/src/commands/prepend.rs index 24205be302..9ac2732ccb 100644 --- a/crates/nu-cli/src/commands/prepend.rs +++ b/crates/nu-cli/src/commands/prepend.rs @@ -35,6 +35,13 @@ impl WholeStreamCommand for Prepend { ) -> Result { args.process(registry, prepend)?.run() } + + fn examples(&self) -> &[Example] { + &[Example { + description: "Add something to the end of a list or table", + example: "echo [2 3 4] | prepend 4", + }] + } } fn prepend( diff --git a/crates/nu-cli/src/prelude.rs b/crates/nu-cli/src/prelude.rs index cba240853d..e17b97f777 100644 --- a/crates/nu-cli/src/prelude.rs +++ b/crates/nu-cli/src/prelude.rs @@ -72,6 +72,7 @@ pub(crate) use nu_protocol::{errln, out, outln}; use nu_source::HasFallibleSpan; pub(crate) use crate::commands::command::{CommandArgs, RawCommandArgs, RunnableContext}; +pub(crate) use crate::commands::Example; pub(crate) use crate::context::CommandRegistry; pub(crate) use crate::context::Context; pub(crate) use crate::data::config;