aboutsummaryrefslogtreecommitdiffstats
path: root/src/parser.rs
blob: 7a7ec98dfaddabb4b938799457587b2bdb27cde1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use snafu::OptionExt as _;

#[derive(Debug, snafu::Snafu)]
pub enum Error {
    #[snafu(display("No command given"))]
    CommandRequired,
}

pub type Result<T> = std::result::Result<T, Error>;

pub fn parse(line: &str) -> Result<(String, Vec<String>)> {
    // TODO
    let mut tokens = line
        .split_whitespace()
        .map(std::string::ToString::to_string);
    let cmd = tokens.next().context(CommandRequired)?;
    Ok((cmd, tokens.collect()))
}