pub struct Command<Context, E> { /* private fields */ }
Expand description
Struct to define a command in the REPL
Implementations§
source§impl<Context, E> Command<Context, E>
impl<Context, E> Command<Context, E>
sourcepub fn new(name: &str, callback: Callback<Context, E>) -> Self
pub fn new(name: &str, callback: Callback<Context, E>) -> Self
Create a new command with the given name and callback function
Examples found in repository?
More examples
examples/custom_prompt.rs (line 28)
21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_prompt(&CustomPrompt)
.with_version("v0.1.0")
.with_description("My very cool app")
.add_command(
Command::new("hello", hello)
.with_parameter(Parameter::new("who").set_required(true)?)?
.with_help("Greetings!"),
);
repl.run()
}
examples/with_context.rs (line 39)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn main() -> Result<()> {
let mut repl = Repl::new(Context::default())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.use_completion(true)
.add_command(
Command::new("append", append)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Append name to end of list"),
)
.add_command(
Command::new("prepend", prepend)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Prepend name to front of list"),
);
repl.run()
}
examples/no_context.rs (line 28)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.add_command(
Command::new("add", add)
.with_parameter(Parameter::new("first").set_required(true)?)?
.with_parameter(Parameter::new("second").set_required(true)?)?
.with_help("Add two numbers together"),
)
.add_command(
Command::new("hello", hello)
.with_parameter(Parameter::new("who").set_required(true)?)?
.with_help("Greetings!"),
);
repl.run()
}
sourcepub fn with_parameter(self, parameter: Parameter) -> Result<Command<Context, E>>
pub fn with_parameter(self, parameter: Parameter) -> Result<Command<Context, E>>
Add a parameter to the command. The order of the parameters is the same as the order in which this is called for each parameter.
Examples found in repository?
examples/custom_prompt.rs (line 29)
21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_prompt(&CustomPrompt)
.with_version("v0.1.0")
.with_description("My very cool app")
.add_command(
Command::new("hello", hello)
.with_parameter(Parameter::new("who").set_required(true)?)?
.with_help("Greetings!"),
);
repl.run()
}
More examples
examples/with_context.rs (line 40)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn main() -> Result<()> {
let mut repl = Repl::new(Context::default())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.use_completion(true)
.add_command(
Command::new("append", append)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Append name to end of list"),
)
.add_command(
Command::new("prepend", prepend)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Prepend name to front of list"),
);
repl.run()
}
examples/no_context.rs (line 29)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.add_command(
Command::new("add", add)
.with_parameter(Parameter::new("first").set_required(true)?)?
.with_parameter(Parameter::new("second").set_required(true)?)?
.with_help("Add two numbers together"),
)
.add_command(
Command::new("hello", hello)
.with_parameter(Parameter::new("who").set_required(true)?)?
.with_help("Greetings!"),
);
repl.run()
}
sourcepub fn with_help(self, help: &str) -> Command<Context, E>
pub fn with_help(self, help: &str) -> Command<Context, E>
Add a help summary for the command
Examples found in repository?
More examples
examples/custom_prompt.rs (line 30)
21 22 23 24 25 26 27 28 29 30 31 32 33
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_prompt(&CustomPrompt)
.with_version("v0.1.0")
.with_description("My very cool app")
.add_command(
Command::new("hello", hello)
.with_parameter(Parameter::new("who").set_required(true)?)?
.with_help("Greetings!"),
);
repl.run()
}
examples/with_context.rs (line 41)
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn main() -> Result<()> {
let mut repl = Repl::new(Context::default())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.use_completion(true)
.add_command(
Command::new("append", append)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Append name to end of list"),
)
.add_command(
Command::new("prepend", prepend)
.with_parameter(Parameter::new("name").set_required(true)?)?
.with_help("Prepend name to front of list"),
);
repl.run()
}
examples/no_context.rs (line 31)
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
fn main() -> Result<()> {
let mut repl = Repl::new(())
.with_name("MyApp")
.with_version("v0.1.0")
.with_description("My very cool app")
.add_command(
Command::new("add", add)
.with_parameter(Parameter::new("first").set_required(true)?)?
.with_parameter(Parameter::new("second").set_required(true)?)?
.with_help("Add two numbers together"),
)
.add_command(
Command::new("hello", hello)
.with_parameter(Parameter::new("who").set_required(true)?)?
.with_help("Greetings!"),
);
repl.run()
}