Add some examples (#1821)

* Adds some examples

* Run rustfmt

* Fixed a few descriptions in the examples
This commit is contained in:
Joseph T. Lyons 2020-05-18 03:11:37 -04:00 committed by GitHub
parent c475be2df8
commit 334685af23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 57 additions and 0 deletions

View file

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

View file

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

View file

@ -34,7 +34,15 @@ impl WholeStreamCommand for Touch {
) -> Result<OutputStream, ShellError> {
touch(args, registry)
}
fn examples(&self) -> &[Example] {
&[Example {
description: "Creates \"fixture.json\"",
example: "touch fixture.json",
}]
}
}
fn touch(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
let registry = registry.clone();
let stream = async_stream! {

View file

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

View file

@ -26,6 +26,13 @@ impl WholeStreamCommand for Version {
) -> Result<OutputStream, ShellError> {
version(args, registry)
}
fn examples(&self) -> &[Example] {
&[Example {
description: "Display Nu version",
example: "version",
}]
}
}
pub fn version(args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream, ShellError> {

View file

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