Runner

Struct Runner 

Source
pub struct Runner { /* private fields */ }

Implementations§

Source§

impl Runner

Source

pub fn new() -> Self

Creates a new instance of the runner and sets all default values

Examples found in repository?
examples/pong_custom_handler.rs (line 17)
16fn main() {
17    let mut runner = Runner::new();
18    runner.enable_custom_executor(execute);
19    runner.run();
20}
More examples
Hide additional examples
examples/default_no_argument_message.rs (line 11)
9fn main() {
10
11    let mut runner = Runner::new();
12    runner.enable_command_handler(CommandHandlerArguments {
13        commands: vec![],
14        default_no_argument_callback: Some(default_callback),
15        flags: vec![]
16    });
17    runner.run();
18}
examples/project_meta_data.rs (line 12)
5fn main() {
6
7    let meta_data = ApplicationMetaData::new(
8        "Test CLI".to_string(),
9        "A test application".to_string()
10    );
11
12    let mut runner = Runner::new();
13    runner.set_meta_data(meta_data);
14    runner.enable_command_handler(CommandHandlerArguments {
15        commands: vec![],
16        default_no_argument_callback: None,
17        flags: vec![]
18    });
19    runner.run();
20}
examples/pong_default.rs (line 26)
15fn main() {
16
17    // defines the base command
18    let pong_command = Command::new(
19        "Pong".to_string(),
20        "Pong command".to_string(),
21        "usage".to_string(),
22        executor,
23        "ping".to_string()
24    );
25
26    let mut runner = Runner::new();
27    runner.enable_command_handler(CommandHandlerArguments {
28        commands: vec![pong_command],
29        default_no_argument_callback: None,
30        flags: vec![]
31    });
32     runner.run();
33}
examples/flag_values.rs (line 29)
12fn main() {
13
14    let command = Command::new(
15        "Test".to_string(),
16        "test command".to_string(),
17        "normal usage".to_string(),
18        executor,
19        "test".to_string()
20    );
21
22    let flag = Flag::new(
23        "testFlag".to_string(),
24        vec!["tf".to_string()],
25        true
26    );
27
28
29    let mut runner = Runner::new();
30    runner.enable_command_handler(CommandHandlerArguments {
31        commands: vec![command],
32        default_no_argument_callback: None,
33        flags: vec![flag]
34    });
35    runner.run();
36}
examples/flags.rs (line 29)
12fn main() {
13
14    let command = Command::new(
15        "Test".to_string(),
16        "test command".to_string(),
17        "normal usage".to_string(),
18        executor,
19        "test".to_string()
20    );
21
22    let flag = Flag::new(
23        "testFlag".to_string(),
24        vec!["tf".to_string()],
25        false
26    );
27
28
29    let mut runner = Runner::new();
30    runner.enable_command_handler(CommandHandlerArguments {
31        commands: vec![command],
32        default_no_argument_callback: None,
33        flags: vec![flag]
34    });
35    runner.run();
36}
Source

pub fn enable_command_handler(&mut self, config: CommandHandlerArguments)

Enables the internal command handler And sets the provided arguments of the command handler

NOTE: This method that should be executed as final step, because it depends on steps before.

Examples found in repository?
examples/default_no_argument_message.rs (lines 12-16)
9fn main() {
10
11    let mut runner = Runner::new();
12    runner.enable_command_handler(CommandHandlerArguments {
13        commands: vec![],
14        default_no_argument_callback: Some(default_callback),
15        flags: vec![]
16    });
17    runner.run();
18}
More examples
Hide additional examples
examples/project_meta_data.rs (lines 14-18)
5fn main() {
6
7    let meta_data = ApplicationMetaData::new(
8        "Test CLI".to_string(),
9        "A test application".to_string()
10    );
11
12    let mut runner = Runner::new();
13    runner.set_meta_data(meta_data);
14    runner.enable_command_handler(CommandHandlerArguments {
15        commands: vec![],
16        default_no_argument_callback: None,
17        flags: vec![]
18    });
19    runner.run();
20}
examples/pong_default.rs (lines 27-31)
15fn main() {
16
17    // defines the base command
18    let pong_command = Command::new(
19        "Pong".to_string(),
20        "Pong command".to_string(),
21        "usage".to_string(),
22        executor,
23        "ping".to_string()
24    );
25
26    let mut runner = Runner::new();
27    runner.enable_command_handler(CommandHandlerArguments {
28        commands: vec![pong_command],
29        default_no_argument_callback: None,
30        flags: vec![]
31    });
32     runner.run();
33}
examples/flag_values.rs (lines 30-34)
12fn main() {
13
14    let command = Command::new(
15        "Test".to_string(),
16        "test command".to_string(),
17        "normal usage".to_string(),
18        executor,
19        "test".to_string()
20    );
21
22    let flag = Flag::new(
23        "testFlag".to_string(),
24        vec!["tf".to_string()],
25        true
26    );
27
28
29    let mut runner = Runner::new();
30    runner.enable_command_handler(CommandHandlerArguments {
31        commands: vec![command],
32        default_no_argument_callback: None,
33        flags: vec![flag]
34    });
35    runner.run();
36}
examples/flags.rs (lines 30-34)
12fn main() {
13
14    let command = Command::new(
15        "Test".to_string(),
16        "test command".to_string(),
17        "normal usage".to_string(),
18        executor,
19        "test".to_string()
20    );
21
22    let flag = Flag::new(
23        "testFlag".to_string(),
24        vec!["tf".to_string()],
25        false
26    );
27
28
29    let mut runner = Runner::new();
30    runner.enable_command_handler(CommandHandlerArguments {
31        commands: vec![command],
32        default_no_argument_callback: None,
33        flags: vec![flag]
34    });
35    runner.run();
36}
Source

pub fn enable_custom_executor(&mut self, executor: fn(arguments: Args))

Sets the custom executor that can contain any argument based operation with the system.

Examples found in repository?
examples/pong_custom_handler.rs (line 18)
16fn main() {
17    let mut runner = Runner::new();
18    runner.enable_custom_executor(execute);
19    runner.run();
20}
Source

pub fn set_meta_data(&mut self, data: ApplicationMetaData)

Sets the meta data of the application

Examples found in repository?
examples/project_meta_data.rs (line 13)
5fn main() {
6
7    let meta_data = ApplicationMetaData::new(
8        "Test CLI".to_string(),
9        "A test application".to_string()
10    );
11
12    let mut runner = Runner::new();
13    runner.set_meta_data(meta_data);
14    runner.enable_command_handler(CommandHandlerArguments {
15        commands: vec![],
16        default_no_argument_callback: None,
17        flags: vec![]
18    });
19    runner.run();
20}
Source

pub fn run(&mut self)

Executes the main runner. If there is a command handler provided, the command handler will be used for executing the commands. Otherwise a custom handler has been provided that is executed

Examples found in repository?
examples/pong_custom_handler.rs (line 19)
16fn main() {
17    let mut runner = Runner::new();
18    runner.enable_custom_executor(execute);
19    runner.run();
20}
More examples
Hide additional examples
examples/default_no_argument_message.rs (line 17)
9fn main() {
10
11    let mut runner = Runner::new();
12    runner.enable_command_handler(CommandHandlerArguments {
13        commands: vec![],
14        default_no_argument_callback: Some(default_callback),
15        flags: vec![]
16    });
17    runner.run();
18}
examples/project_meta_data.rs (line 19)
5fn main() {
6
7    let meta_data = ApplicationMetaData::new(
8        "Test CLI".to_string(),
9        "A test application".to_string()
10    );
11
12    let mut runner = Runner::new();
13    runner.set_meta_data(meta_data);
14    runner.enable_command_handler(CommandHandlerArguments {
15        commands: vec![],
16        default_no_argument_callback: None,
17        flags: vec![]
18    });
19    runner.run();
20}
examples/pong_default.rs (line 32)
15fn main() {
16
17    // defines the base command
18    let pong_command = Command::new(
19        "Pong".to_string(),
20        "Pong command".to_string(),
21        "usage".to_string(),
22        executor,
23        "ping".to_string()
24    );
25
26    let mut runner = Runner::new();
27    runner.enable_command_handler(CommandHandlerArguments {
28        commands: vec![pong_command],
29        default_no_argument_callback: None,
30        flags: vec![]
31    });
32     runner.run();
33}
examples/flag_values.rs (line 35)
12fn main() {
13
14    let command = Command::new(
15        "Test".to_string(),
16        "test command".to_string(),
17        "normal usage".to_string(),
18        executor,
19        "test".to_string()
20    );
21
22    let flag = Flag::new(
23        "testFlag".to_string(),
24        vec!["tf".to_string()],
25        true
26    );
27
28
29    let mut runner = Runner::new();
30    runner.enable_command_handler(CommandHandlerArguments {
31        commands: vec![command],
32        default_no_argument_callback: None,
33        flags: vec![flag]
34    });
35    runner.run();
36}
examples/flags.rs (line 35)
12fn main() {
13
14    let command = Command::new(
15        "Test".to_string(),
16        "test command".to_string(),
17        "normal usage".to_string(),
18        executor,
19        "test".to_string()
20    );
21
22    let flag = Flag::new(
23        "testFlag".to_string(),
24        vec!["tf".to_string()],
25        false
26    );
27
28
29    let mut runner = Runner::new();
30    runner.enable_command_handler(CommandHandlerArguments {
31        commands: vec![command],
32        default_no_argument_callback: None,
33        flags: vec![flag]
34    });
35    runner.run();
36}

Auto Trait Implementations§

§

impl Freeze for Runner

§

impl RefUnwindSafe for Runner

§

impl Send for Runner

§

impl Sync for Runner

§

impl Unpin for Runner

§

impl UnwindSafe for Runner

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

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 T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.