Add a batch of help examples (#1759)

This commit is contained in:
Jonathan Turner 2020-05-12 17:17:17 +12:00 committed by GitHub
parent c3535b5c67
commit 0b520eeaf0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 163 additions and 0 deletions

View file

@ -72,6 +72,39 @@ impl WholeStreamCommand for Config {
) -> Result<OutputStream, ShellError> {
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(

View file

@ -42,6 +42,19 @@ impl WholeStreamCommand for Cpy {
) -> Result<OutputStream, ShellError> {
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<OutputStream, ShellError> {

View file

@ -40,6 +40,13 @@ impl WholeStreamCommand for Default {
) -> Result<OutputStream, ShellError> {
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(

View file

@ -36,6 +36,19 @@ impl WholeStreamCommand for Drop {
) -> Result<OutputStream, ShellError> {
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<OutputStream, ShellError> {

View file

@ -78,6 +78,13 @@ impl WholeStreamCommand for Du {
) -> Result<OutputStream, ShellError> {
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<OutputStream, ShellError> {

View file

@ -41,6 +41,13 @@ impl WholeStreamCommand for Each {
) -> Result<OutputStream, ShellError> {
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 {

View file

@ -30,6 +30,19 @@ impl WholeStreamCommand for Echo {
) -> Result<OutputStream, ShellError> {
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<OutputStream, ShellError> {

View file

@ -40,6 +40,19 @@ impl WholeStreamCommand for Enter {
) -> Result<OutputStream, ShellError> {
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(

View file

@ -26,6 +26,19 @@ impl WholeStreamCommand for Exit {
) -> Result<OutputStream, ShellError> {
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<OutputStream, ShellError> {

View file

@ -36,6 +36,19 @@ impl WholeStreamCommand for First {
) -> Result<OutputStream, ShellError> {
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(

View file

@ -38,6 +38,13 @@ impl WholeStreamCommand for Format {
) -> Result<OutputStream, ShellError> {
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(

View file

@ -28,6 +28,13 @@ impl WholeStreamCommand for FromBSON {
) -> Result<OutputStream, ShellError> {
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<Vec<Value>, ShellError> {

View file

@ -43,6 +43,23 @@ impl WholeStreamCommand for FromCSV {
) -> Result<OutputStream, ShellError> {
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(