forked from extern/nushell
Add a batch of help examples (#1755)
This commit is contained in:
parent
c5ea4a31bd
commit
8b9a8daa1d
@ -1,4 +1,4 @@
|
||||
use crate::commands::{Example, WholeStreamCommand};
|
||||
use crate::commands::WholeStreamCommand;
|
||||
use crate::context::CommandRegistry;
|
||||
use crate::prelude::*;
|
||||
use nu_errors::ShellError;
|
||||
|
@ -35,6 +35,13 @@ impl WholeStreamCommand for Append {
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
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(
|
||||
|
@ -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 {
|
||||
|
@ -43,6 +43,19 @@ impl WholeStreamCommand for Cal {
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
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<OutputStream, ShellError> {
|
||||
|
@ -24,6 +24,13 @@ impl WholeStreamCommand for Calc {
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
args.process(registry, calc)?.run()
|
||||
}
|
||||
|
||||
fn examples(&self) -> &[Example] {
|
||||
&[Example {
|
||||
description: "Calculate math in the pipeline",
|
||||
example: "echo '10 / 4' | calc",
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn calc(
|
||||
|
@ -38,6 +38,27 @@ impl WholeStreamCommand for Cd {
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
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<OutputStream, ShellError> {
|
||||
|
@ -23,6 +23,12 @@ impl WholeStreamCommand for Clear {
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
clear(args, registry)
|
||||
}
|
||||
fn examples(&self) -> &[Example] {
|
||||
&[Example {
|
||||
description: "Clear the screen",
|
||||
example: "clear",
|
||||
}]
|
||||
}
|
||||
}
|
||||
fn clear(_args: CommandArgs, _registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
||||
if cfg!(windows) {
|
||||
|
@ -34,6 +34,13 @@ pub mod clipboard {
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
args.process(registry, clip)?.run()
|
||||
}
|
||||
|
||||
fn examples(&self) -> &[Example] {
|
||||
&[Example {
|
||||
description: "Save text to the clipboard",
|
||||
example: "echo 'secret value' | clip",
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clip(
|
||||
|
@ -33,6 +33,13 @@ impl WholeStreamCommand for Compact {
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
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(
|
||||
|
@ -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<OutputStream, ShellError> {
|
||||
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(
|
||||
|
@ -35,6 +35,13 @@ impl WholeStreamCommand for Prepend {
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
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(
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user