Struct repl_rs::Command

source ·
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>

source

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?
examples/custom_error.rs (line 45)
40
41
42
43
44
45
46
47
fn main() -> Result<(), repl_rs::Error> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(Command::new("hello", hello).with_help("Do nothing, unsuccessfully"));
    repl.run()
}
More examples
Hide additional 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()
}
source

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
Hide additional 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()
}
source

pub fn with_help(self, help: &str) -> Command<Context, E>

Add a help summary for the command

Examples found in repository?
examples/custom_error.rs (line 45)
40
41
42
43
44
45
46
47
fn main() -> Result<(), repl_rs::Error> {
    let mut repl = Repl::new(())
        .with_name("MyApp")
        .with_version("v0.1.0")
        .with_description("My very cool app")
        .add_command(Command::new("hello", hello).with_help("Do nothing, unsuccessfully"));
    repl.run()
}
More examples
Hide additional 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()
}

Trait Implementations§

source§

impl<Context, E> Debug for Command<Context, E>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Context, E> PartialEq<Command<Context, E>> for Command<Context, E>

source§

fn eq(&self, other: &Command<Context, E>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<Context, E> RefUnwindSafe for Command<Context, E>

§

impl<Context, E> Send for Command<Context, E>

§

impl<Context, E> Sync for Command<Context, E>

§

impl<Context, E> Unpin for Command<Context, E>

§

impl<Context, E> UnwindSafe for Command<Context, E>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.