[][src]Struct cmdtree::Commander

pub struct Commander<'r> { /* fields omitted */ }

A constructed command tree.

Most of the time a user will want to use run() which will handle all the parsing and navigating of the tree. Alternatively, parse_line can be used to simulate a read input and update the command tree position.

To construct a command tree, look at the builder module.

Methods

impl<'r> Commander<'r>[src]

pub fn parse_line<W: Write>(
    &mut self,
    line: &str,
    colourise: bool,
    writer: &mut W
) -> LineResult
[src]

Parse a line of commands and updates the Commander state.

Parsing a line is akin to sending an input line to the commander in the run loop. Commands are space separated, and executed within this function, any actions that are specified will be invoked.

Most branches result in a LineResult::Continue apart from an exit command which will result in a LineResult::Exit. It is up to the developer to decide on the behaviour.

Example

use cmdtree::*;
let mut cmder = Builder::default_config("base")
    .begin_class("one", "")
    .begin_class("two", "")
    .add_action("echo", "", |args| println!("{}", args.join(" ")))
    .into_commander().unwrap();

assert_eq!(cmder.path(), "base");
cmder.parse_line("one two", true,  &mut std::io::sink());
assert_eq!(cmder.path(), "base.one.two");
cmder.parse_line("echo Hello, world!", true, &mut std::io::sink());	// should print "Hello, world!"

impl<'r> Commander<'r>[src]

pub fn path(&self) -> &str[src]

Return the path of the current class, separated by ..

Example

use cmdtree::*;
let mut cmder = Builder::default_config("base")
    .begin_class("one", "")
    .begin_class("two", "")
    .into_commander().unwrap();

assert_eq!(cmder.path(), "base");
cmder.parse_line("one two", true,  &mut std::io::sink());
assert_eq!(cmder.path(), "base.one.two");

pub fn run(self)[src]

Run the Commander interactively. Consumes the instance, and blocks the thread until the loop is exited. Reads from stdin using linefeed::Interface.

This is the most simple way of using a Commander.

Auto Trait Implementations

impl<'r> !Send for Commander<'r>

impl<'r> !Sync for Commander<'r>

Blanket Implementations

impl<T> From for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

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

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

The type returned in the event of a conversion error.