aboutsummaryrefslogtreecommitdiffstats
path: root/src/parser.rs
blob: 9d4125f5cc40ebf45e835fd34415f66cb58cfff4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use snafu::{OptionExt, Snafu};

#[derive(Debug, 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(|s| s.to_string());
    let cmd = tokens.next().context(CommandRequired)?;
    Ok((cmd, tokens.collect()))
}