diff --git a/crates/nu-cli/src/commands/config.rs b/crates/nu-cli/src/commands/config.rs index c0838eb013..8e62e2b0b7 100644 --- a/crates/nu-cli/src/commands/config.rs +++ b/crates/nu-cli/src/commands/config.rs @@ -72,6 +72,39 @@ impl WholeStreamCommand for Config { ) -> Result { args.process(registry, config)?.run() } + + fn examples(&self) -> &[Example] { + &[ + Example { + description: "See all config values", + example: "config", + }, + Example { + description: "Set completion_mode to circular", + example: "config --set [completion_mode circular]", + }, + Example { + description: "Store the contents of the pipeline as a path", + example: "echo ['/usr/bin' '/bin'] | config --set_into path", + }, + Example { + description: "Get the current startup commands", + example: "config --get startup", + }, + Example { + description: "Remove the startup commands", + example: "config --remove startup", + }, + Example { + description: "Clear the config (be careful!)", + example: "config --clear", + }, + Example { + description: "Get the path to the current config file", + example: "config --path", + }, + ] + } } pub fn config( diff --git a/crates/nu-cli/src/commands/cp.rs b/crates/nu-cli/src/commands/cp.rs index 8524ce6bc5..946565edc0 100644 --- a/crates/nu-cli/src/commands/cp.rs +++ b/crates/nu-cli/src/commands/cp.rs @@ -42,6 +42,19 @@ impl WholeStreamCommand for Cpy { ) -> Result { args.process(registry, cp)?.run() } + + fn examples(&self) -> &[Example] { + &[ + Example { + description: "Copy myfile to dir_b", + example: "cp myfile dir_b", + }, + Example { + description: "Recursively copy dir_a to dir_b", + example: "cp -r dir_a dir_b", + }, + ] + } } pub fn cp(args: CopyArgs, context: RunnableContext) -> Result { diff --git a/crates/nu-cli/src/commands/default.rs b/crates/nu-cli/src/commands/default.rs index 4a7b8ecaab..27d6364f7c 100644 --- a/crates/nu-cli/src/commands/default.rs +++ b/crates/nu-cli/src/commands/default.rs @@ -40,6 +40,13 @@ impl WholeStreamCommand for Default { ) -> Result { args.process(registry, default)?.run() } + + fn examples(&self) -> &[Example] { + &[Example { + description: "Give a default 'target' to all file entries", + example: "ls -af | default target 'nothing'", + }] + } } fn default( diff --git a/crates/nu-cli/src/commands/drop.rs b/crates/nu-cli/src/commands/drop.rs index ea3eac6b38..3f7faddc44 100644 --- a/crates/nu-cli/src/commands/drop.rs +++ b/crates/nu-cli/src/commands/drop.rs @@ -36,6 +36,19 @@ impl WholeStreamCommand for Drop { ) -> Result { args.process(registry, drop)?.run() } + + fn examples(&self) -> &[Example] { + &[ + Example { + description: "Remove the last item of a list/table", + example: "echo [1 2 3] | drop", + }, + Example { + description: "Remove the last 2 items of a list/table", + example: "echo [1 2 3] | drop 2", + }, + ] + } } fn drop(DropArgs { rows }: DropArgs, context: RunnableContext) -> Result { diff --git a/crates/nu-cli/src/commands/du.rs b/crates/nu-cli/src/commands/du.rs index 5dd3f7793e..b3924fb187 100644 --- a/crates/nu-cli/src/commands/du.rs +++ b/crates/nu-cli/src/commands/du.rs @@ -78,6 +78,13 @@ impl WholeStreamCommand for Du { ) -> Result { args.process(registry, du)?.run() } + + fn examples(&self) -> &[Example] { + &[Example { + description: "Disk usage of the current directory", + example: "du *", + }] + } } fn du(args: DuArgs, ctx: RunnableContext) -> Result { diff --git a/crates/nu-cli/src/commands/each.rs b/crates/nu-cli/src/commands/each.rs index c863367d19..305b39a4af 100644 --- a/crates/nu-cli/src/commands/each.rs +++ b/crates/nu-cli/src/commands/each.rs @@ -41,6 +41,13 @@ impl WholeStreamCommand for Each { ) -> Result { Ok(args.process_raw(registry, each)?.run()) } + + fn examples(&self) -> &[Example] { + &[Example { + description: "Print the name of each file", + example: "ls | each { echo $it.name }", + }] + } } fn is_expanded_it_usage(head: &SpannedExpression) -> bool { diff --git a/crates/nu-cli/src/commands/echo.rs b/crates/nu-cli/src/commands/echo.rs index 85d5008008..e0cfe3e538 100644 --- a/crates/nu-cli/src/commands/echo.rs +++ b/crates/nu-cli/src/commands/echo.rs @@ -30,6 +30,19 @@ impl WholeStreamCommand for Echo { ) -> Result { args.process(registry, echo)?.run() } + + fn examples(&self) -> &[Example] { + &[ + Example { + description: "Put a hello message in the pipeline", + example: "echo 'hello'", + }, + Example { + description: "Print the value of the special '$nu' variable", + example: "echo $nu", + }, + ] + } } fn echo(args: EchoArgs, _: RunnableContext) -> Result { diff --git a/crates/nu-cli/src/commands/enter.rs b/crates/nu-cli/src/commands/enter.rs index 66f7e4698d..962c61de3a 100644 --- a/crates/nu-cli/src/commands/enter.rs +++ b/crates/nu-cli/src/commands/enter.rs @@ -40,6 +40,19 @@ impl WholeStreamCommand for Enter { ) -> Result { Ok(args.process_raw(registry, enter)?.run()) } + + fn examples(&self) -> &[Example] { + &[ + Example { + description: "Enter a path as a new shell", + example: "enter ../projectB", + }, + Example { + description: "Enter a file as a new shell", + example: "enter package.json", + }, + ] + } } fn enter( diff --git a/crates/nu-cli/src/commands/exit.rs b/crates/nu-cli/src/commands/exit.rs index a775116777..1345672104 100644 --- a/crates/nu-cli/src/commands/exit.rs +++ b/crates/nu-cli/src/commands/exit.rs @@ -26,6 +26,19 @@ impl WholeStreamCommand for Exit { ) -> Result { exit(args, registry) } + + fn examples(&self) -> &[Example] { + &[ + Example { + description: "Exit the current shell", + example: "exit", + }, + Example { + description: "Exit all shells (exiting Nu)", + example: "exit --now", + }, + ] + } } pub fn exit(args: CommandArgs, registry: &CommandRegistry) -> Result { diff --git a/crates/nu-cli/src/commands/first.rs b/crates/nu-cli/src/commands/first.rs index 09096bdd63..010e0a7320 100644 --- a/crates/nu-cli/src/commands/first.rs +++ b/crates/nu-cli/src/commands/first.rs @@ -36,6 +36,19 @@ impl WholeStreamCommand for First { ) -> Result { args.process(registry, first)?.run() } + + fn examples(&self) -> &[Example] { + &[ + Example { + description: "Return the first item of a list/table", + example: "echo [1 2 3] | first", + }, + Example { + description: "Return the first 2 items of a list/table", + example: "echo [1 2 3] | first 2", + }, + ] + } } fn first( diff --git a/crates/nu-cli/src/commands/format.rs b/crates/nu-cli/src/commands/format.rs index 1b714de586..2ff3a5e62b 100644 --- a/crates/nu-cli/src/commands/format.rs +++ b/crates/nu-cli/src/commands/format.rs @@ -38,6 +38,13 @@ impl WholeStreamCommand for Format { ) -> Result { args.process(registry, format_command)?.run() } + + fn examples(&self) -> &[Example] { + &[Example { + description: "Print filenames with their sizes", + example: "ls | format '{name}: {size}'", + }] + } } fn format_command( diff --git a/crates/nu-cli/src/commands/from_bson.rs b/crates/nu-cli/src/commands/from_bson.rs index 98a29bde54..8b20d9549a 100644 --- a/crates/nu-cli/src/commands/from_bson.rs +++ b/crates/nu-cli/src/commands/from_bson.rs @@ -28,6 +28,13 @@ impl WholeStreamCommand for FromBSON { ) -> Result { from_bson(args, registry) } + + fn examples(&self) -> &[Example] { + &[Example { + description: "Convert bson data to a table", + example: "open file.bin | from bson", + }] + } } fn bson_array(input: &[Bson], tag: Tag) -> Result, ShellError> { diff --git a/crates/nu-cli/src/commands/from_csv.rs b/crates/nu-cli/src/commands/from_csv.rs index 81b3bf0af0..019bcecde5 100644 --- a/crates/nu-cli/src/commands/from_csv.rs +++ b/crates/nu-cli/src/commands/from_csv.rs @@ -43,6 +43,23 @@ impl WholeStreamCommand for FromCSV { ) -> Result { args.process(registry, from_csv)?.run() } + + fn examples(&self) -> &[Example] { + &[ + Example { + description: "Convert comma-separated data to a table", + example: "open data.txt | from csv", + }, + Example { + description: "Convert comma-separated data to a table, ignoring headers", + example: "open data.txt | from csv --headerless", + }, + Example { + description: "Convert semicolon-separated data to a table", + example: "open data.txt | from csv --separator ';'", + }, + ] + } } fn from_csv(