forked from extern/nushell
Add examples to commands (#1752)
* Pass &dyn WholeStreamCommand to get_help * Add an optional example to the WholeStreamCommand trait * Add an example to the alias command
This commit is contained in:
@ -350,6 +350,11 @@ impl EvaluatedCommandArgs {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Example {
|
||||
pub example: &'static str,
|
||||
pub description: &'static str,
|
||||
}
|
||||
|
||||
pub trait WholeStreamCommand: Send + Sync {
|
||||
fn name(&self) -> &str;
|
||||
|
||||
@ -368,6 +373,10 @@ pub trait WholeStreamCommand: Send + Sync {
|
||||
fn is_binary(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn examples(&self) -> &[Example] {
|
||||
&[]
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -407,7 +416,7 @@ impl Command {
|
||||
|
||||
pub fn run(&self, args: CommandArgs, registry: &CommandRegistry) -> OutputStream {
|
||||
if args.call_info.switch_present("help") {
|
||||
get_help(self.name(), self.usage(), self.signature(), registry).into()
|
||||
get_help(&*self.0, registry).into()
|
||||
} else {
|
||||
match self.0.run(args, registry) {
|
||||
Ok(stream) => stream,
|
||||
@ -419,6 +428,10 @@ impl Command {
|
||||
pub fn is_binary(&self) -> bool {
|
||||
self.0.is_binary()
|
||||
}
|
||||
|
||||
pub fn stream_command(&self) -> &dyn WholeStreamCommand {
|
||||
&*self.0
|
||||
}
|
||||
}
|
||||
|
||||
pub struct FnFilterCommand {
|
||||
|
Reference in New Issue
Block a user