[][src]Struct medusa::CommandLine

pub struct CommandLine { /* fields omitted */ }

Struct that defines a CLI program in a programmatic way.

Methods

impl CommandLine[src]

pub fn new() -> CommandLine[src]

Create a new empty CommandLine instance.

Example

use medusa::CommandLine;

// code ...

let mut cli: CommandLine = CommandLine::new();

pub fn set_handler(&mut self, handler: Handler)[src]

Set handler for the CommandLine istance using Handler instance.

Example

use medusa::{CommandLine, Handler};

fn show_help() {
  println!("This is help message!");
}

let mut handler: Handler = Handler::new();
// code ...

let mut cli: CommandLine = CommandLine::new();
cli.set_handler(handler);

pub fn run(&self, args: Args)[src]

Run the CommandLine instance with arguments passed to it in form of std::env::Args. Handler instance registered to this CommandLine will be checked for each of its action key to parse or process passed arguments when the CLI is executed.

Example

// code ...

use medusa::{CommandLine, Handler};

use std::env;

// code ...

let mut handler: Handler = Handler::new();
// code ...

let mut cli: CommandLine = CommandLine::new();
cli.set_handler(handler);
cli.run(env::args());

pub fn set_default_command(&mut self, function: fn())[src]

Set default function or action by calling it when the CLI are executed with no arguments passed at all. Usually this will show help or usage message. For example, a help function could be defined and what's next are to set the CLI's default function (action) "pointing" to that function. Since the CLI is executed with no arguments passed, the function parameter used for this method implementation is in form of fn().

Example

// code ...

use medusa::{CommandLine, Handler};

use std::env;

fn show_help() {
  println!("This is help message!");
}

// code ...

let mut handler: Handler = Handler::new();
// code ...

let mut cli: CommandLine = CommandLine::new();
cli.set_handler(handler);
cli.set_default_command(show_help);
cli.run(env::args());

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.