diff --git a/Cargo.toml b/Cargo.toml index dbf60d1..0f5c65a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ uuid = "0.8" tui = "0.11" termion = "1.5" -clap = "2.33" +clap = "3.0.0-beta.2" smol = "1.2" diff --git a/src/commands.rs b/src/commands.rs new file mode 100644 index 0000000..5e8b5b9 --- /dev/null +++ b/src/commands.rs @@ -0,0 +1,54 @@ +use clap::{ + App, + AppSettings, + ArgMatches, + Error, +}; + +enum Commands { + +} + +struct CommandParser<'help> { + app: App<'help>, +} + +impl<'help> CommandParser<'help> { + pub fn new() -> Self { + Self { + app: App::new("Commands") + .setting(AppSettings::DisableVersion) + .setting(AppSettings::StrictUtf8) + .setting(AppSettings::ColorAlways) + .setting(AppSettings::NoBinaryName) + .subcommand(App::new("connect")), + } + } + + pub fn parse>(&mut self, iter: I) -> Result { + self.app.try_get_matches_from_mut(iter) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parse_commands_test() { + let mut cmds = CommandParser::new(); + let p = vec!["connect".to_string()]; + let matches = cmds.parse(p).unwrap(); + + assert_eq!(matches.subcommand_name(), Some("connect")); + } + + #[test] + fn fail_parsing_test() { + let mut cmds = CommandParser::new(); + let p = vec!["invalid".to_string()]; + let matches = cmds.parse(p); + + assert!(matches.is_err()) + } +} diff --git a/src/main.rs b/src/main.rs index 460d11f..a577f55 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,17 +38,16 @@ fn main() -> Result<(), io::Error> { .version(env!("CARGO_PKG_VERSION")) .author(env!("CARGO_PKG_AUTHORS")) .about(env!("CARGO_PKG_DESCRIPTION")) - .usage("Press `?` in the GUI to see keybindings") .before_help(BANNER) - .arg(Arg::with_name("config") - .short("c") + .arg(Arg::new("config") + .short('c') .long("config") - .help("Specify configuration file path") + .about("Specify configuration file path") .takes_value(true)) - .arg(Arg::with_name("server") - .short("s") + .arg(Arg::new("server") + .short('s') .long("server") - .help("Connect to the specified address[:port] as server") + .about("Connect to the specified address[:port] as server") .takes_value(true)) .get_matches();