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

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

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.