[][src]Struct slaps::Slaps

pub struct Slaps<'a, 'b> { /* fields omitted */ }

Interactive shell mode using a clap/structopt configuration.

Implementations

impl<'a, 'b> Slaps<'a, 'b>[src]

#[must_use]pub fn with_name(name: &str) -> Self[src]

Creates a new interactive app using the default configuration.

Examples

use slaps::Slaps;

let slaps = Slaps::with_name("slaps");

#[must_use]pub fn with_name_and_config(name: &str, config: Config<'b>) -> Slaps<'a, 'b>[src]

Creates a new interactive app with the given Config.

Examples

use slaps::{Config, ColorMode, Slaps};

let slaps = Slaps::with_name_and_config("slaps", Config::default()
    .color_mode(ColorMode::Disabled));

#[must_use]pub fn command<T: 'b>(self, command: App<'a, 'b>, handler: T) -> Self where
    T: Fn(&ArgMatches) -> Result<(), ExecutionError> + Send + Sync
[src]

Registers a Clap subcommand configuration with Slaps.

Examples

use clap::App;
use slaps::Slaps;

let slaps = Slaps::with_name("slaps")
    .command(App::new("slap"), |matches| {println!("{:?}", matches); Ok(())} );

pub fn prompt_line(
    &mut self,
    prompt: Option<&str>
) -> Result<String, ReadlineError>
[src]

Prompts the user for a String using the default prompt.

If prompt is None, uses the default from the Config.

Errors

May return a ReadlineError from the internal readline implementation.

pub fn prompt_password(
    &self,
    prompt: Option<&str>
) -> Result<String, ReadlineError>
[src]

Prompts the user for a password.

If prompt is None, uses the default from the Config.

Errors

May return a ReadlineError from the internal readline implementation.

pub fn get_matches<T: AsRef<str>>(
    &mut self,
    input: T
) -> Result<ArgMatches, Error>
[src]

Parses a string directly into a clap::ArgMatches object.

Errors

  • MismatchedQuote parsing failed due to mismatched quotation marks within the input.

Examples

use clap::{App, Arg};
use slaps::Slaps;

let command = App::new("slaps").arg(Arg::with_name("that").long("that").takes_value(true));
let mut slaps = Slaps::with_name("slaps").command(command, |args| Ok(()));
let matches = slaps.get_matches("slaps --that arg").unwrap();

assert_eq!(matches.subcommand_name(), Some("slaps"));
assert_eq!(matches.subcommand_matches("slaps").unwrap().value_of("that"), Some("arg"));

pub fn run(self) -> Result<(), Error>[src]

Starts the main interactive loop, prompting the user for input repeatedly.

Errors

Will return an error when it fails to read more input.

pub fn handle_matches<A: AsRef<OsStr>>(
    &mut self,
    input: &[A]
) -> Result<(), Error>
[src]

Matches a command by parsing command-line arguments from the given input, and executes its associated handler.

Useful for handling commands from std::env::args before switching to interactive mode.

Errors

  • ClapError - the input did not specify a command or failed to parse arguments.
  • ExecutionError - the handler returned an error.

Examples

use slaps::{Config, ExecutionError, Slaps, Error};
use clap::{App, Arg, ErrorKind};

let command = App::new("slaps").arg(
Arg::with_name("this")
    .long("this")
    .takes_value(true)
    .required(true),
);

let mut slaps = Slaps::with_name("slaps").command(command, |args| {
    Err(ExecutionError::GracefulExit)
});
let args = ["prog", "slaps", "--this", "arg"];
let result = slaps.handle_matches(&args[1..]);

match result {
    Err(Error::ClapError(ref e)) => match e.kind {
        ErrorKind::Io | ErrorKind::Format => eprintln!("I/O error: {}", e),
        _ => eprintln!("Error while parsing arguments: {}", e),
    },
    Ok(_) => eprintln!("Command succeeded."),
    Err(ref e) => eprintln!("Command handler failed to execute: {}", e)
}

Trait Implementations

impl<'_, '_> Debug for Slaps<'_, '_>[src]

Auto Trait Implementations

impl<'a, 'b> !RefUnwindSafe for Slaps<'a, 'b>

impl<'a, 'b> !Send for Slaps<'a, 'b>

impl<'a, 'b> !Sync for Slaps<'a, 'b>

impl<'a, 'b> Unpin for Slaps<'a, 'b>

impl<'a, 'b> !UnwindSafe for Slaps<'a, 'b>

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.