[][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.

Note that if using this method, then all existing handler in current CommandLine instance are replaced with the one passed to this method. To add Handler intance into CommandLine instance see append_handler.

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 append_handler(&mut self, handler: Handler)[src]

Append handler for the CommandLine istance using Handler instance.

Note that if using this method, then the Handler instance passed are added to the current CommandLine instance instead of replacing it. If no Handler found in current CommandLine instance then this method will set the current handler to the one passed in.

Example

use medusa::{CommandLine, Handler};

fn print_string(arg: String) {
  println!("Got string : {}", arg);
}

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

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

pub fn run(&mut 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().

By default, if this is not set, the CLI will print all of available function or action that is already set on the CommandLine instance when the binary is executed.

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());

pub fn set_version(&mut self, version: &str)[src]

Set version for the current CLI. By default when creating a new instance of CommandLine the version starts from 0.0.1. Any instance of string can be passed here since currently there are no limitation whether or not to use semantic versioning. For example, a string like v1.9.7-rc.2 can be passed to set the CLI's version.

Example

use medusa::CommandLine;

// code ...

let mut cli: CommandLine = CommandLine::new();
cli.set_version("v1.9.7-rc.2");

pub fn set_name(&mut self, name: &str)[src]

Set the name for the current CLI. By default when creating a new instance of CommandLine the name are medusa as this is the crates name. Any instance of string can be passed here to set the CLI's name. For example, a string like mycli can be passed to set the CLI's name.

Example

use medusa::CommandLine;

// code ...

let mut cli: CommandLine = CommandLine::new();
cli.set_name("mycli");

Trait Implementations

impl Clone for CommandLine[src]

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.