From 334685af23069096e441d92f0e51b9acb90c7473 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Mon, 18 May 2020 03:11:37 -0400 Subject: [PATCH] Add some examples (#1821) * Adds some examples * Run rustfmt * Fixed a few descriptions in the examples --- crates/nu-cli/src/commands/open.rs | 7 +++++++ crates/nu-cli/src/commands/reject.rs | 7 +++++++ crates/nu-cli/src/commands/touch.rs | 8 ++++++++ crates/nu-cli/src/commands/trim.rs | 7 +++++++ crates/nu-cli/src/commands/version.rs | 7 +++++++ crates/nu-cli/src/commands/where_.rs | 21 +++++++++++++++++++++ 6 files changed, 57 insertions(+) diff --git a/crates/nu-cli/src/commands/open.rs b/crates/nu-cli/src/commands/open.rs index c18b9159c1..2bd5459a4b 100644 --- a/crates/nu-cli/src/commands/open.rs +++ b/crates/nu-cli/src/commands/open.rs @@ -43,6 +43,13 @@ impl WholeStreamCommand for Open { ) -> Result { open(args, registry) } + + fn examples(&self) -> &[Example] { + &[Example { + description: "Opens \"users.csv\" and creates a table from the data", + example: "open users.csv", + }] + } } fn open(args: CommandArgs, registry: &CommandRegistry) -> Result { diff --git a/crates/nu-cli/src/commands/reject.rs b/crates/nu-cli/src/commands/reject.rs index fd345860d0..05b7e4705a 100644 --- a/crates/nu-cli/src/commands/reject.rs +++ b/crates/nu-cli/src/commands/reject.rs @@ -32,6 +32,13 @@ impl WholeStreamCommand for Reject { ) -> Result { reject(args, registry) } + + fn examples(&self) -> &[Example] { + &[Example { + description: "Lists the files in a directory without showing the modified column", + example: "ls | reject modified", + }] + } } fn reject(args: CommandArgs, registry: &CommandRegistry) -> Result { diff --git a/crates/nu-cli/src/commands/touch.rs b/crates/nu-cli/src/commands/touch.rs index c688dd3ecd..569d217ab7 100644 --- a/crates/nu-cli/src/commands/touch.rs +++ b/crates/nu-cli/src/commands/touch.rs @@ -34,7 +34,15 @@ impl WholeStreamCommand for Touch { ) -> Result { touch(args, registry) } + + fn examples(&self) -> &[Example] { + &[Example { + description: "Creates \"fixture.json\"", + example: "touch fixture.json", + }] + } } + fn touch(args: CommandArgs, registry: &CommandRegistry) -> Result { let registry = registry.clone(); let stream = async_stream! { diff --git a/crates/nu-cli/src/commands/trim.rs b/crates/nu-cli/src/commands/trim.rs index cbc3f6712a..a803b0e5ea 100644 --- a/crates/nu-cli/src/commands/trim.rs +++ b/crates/nu-cli/src/commands/trim.rs @@ -26,6 +26,13 @@ impl WholeStreamCommand for Trim { ) -> Result { trim(args, registry) } + + fn examples(&self) -> &[Example] { + &[Example { + description: "Trims surrounding whitespace and outputs \"Hello world\"", + example: "echo \" Hello world\" | trim", + }] + } } fn trim_primitive(p: &mut Primitive) { diff --git a/crates/nu-cli/src/commands/version.rs b/crates/nu-cli/src/commands/version.rs index 1e884b6c5e..8bce68c6f8 100644 --- a/crates/nu-cli/src/commands/version.rs +++ b/crates/nu-cli/src/commands/version.rs @@ -26,6 +26,13 @@ impl WholeStreamCommand for Version { ) -> Result { version(args, registry) } + + fn examples(&self) -> &[Example] { + &[Example { + description: "Display Nu version", + example: "version", + }] + } } pub fn version(args: CommandArgs, _registry: &CommandRegistry) -> Result { diff --git a/crates/nu-cli/src/commands/where_.rs b/crates/nu-cli/src/commands/where_.rs index 68f9dcd7e7..29e0c8faf9 100644 --- a/crates/nu-cli/src/commands/where_.rs +++ b/crates/nu-cli/src/commands/where_.rs @@ -36,6 +36,27 @@ impl WholeStreamCommand for Where { ) -> Result { where_command(args, registry) } + + fn examples(&self) -> &[Example] { + &[ + Example { + description: "List all files in the current directory with sizes greater than 2kb", + example: "ls | where size > 2kb", + }, + Example { + description: "List only the files in the current directory", + example: "ls | where type == File", + }, + Example { + description: "List all files with names that contain \"Car\"", + example: "ls | where name =~ \"Car\"", + }, + Example { + description: "List all files that were modified in the last two months", + example: "ls | where modified <= 2M", + }, + ] + } } fn where_command( raw_args: CommandArgs,