diff --git a/crates/nu-cli/src/commands/alias.rs b/crates/nu-cli/src/commands/alias.rs index c7ad0c97c..8c78eac4b 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 c094d02e6..e3b12c748 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 976ff5c29..9b655d686 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 6f54968c4..3f3022aff 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 2785d10cc..0196cd55c 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 8f766545b..3d2a01781 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 21590e10a..eed4fd766 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 5ab7ff79d..2fb112e15 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 240a6a74d..0300c10f8 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 f9f4ca48e..5ed2b0bb8 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 24205be30..9ac2732cc 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 cba240853..e17b97f77 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;