Extract CLI logic to a child project

This commit is contained in:
timvisee 2018-03-08 23:02:06 +01:00
parent 2df0f8d077
commit 7a56dabd39
No known key found for this signature in database
GPG key ID: 109CBA0BF74036C2
11 changed files with 26 additions and 23 deletions

View file

@ -1,35 +0,0 @@
use super::clap::{App, ArgMatches};
use app::*;
use super::cmd_upload::CmdUpload;
/// CLI argument handler.
pub struct Handler<'a> {
/// The CLI matches.
matches: ArgMatches<'a>,
}
impl<'a: 'b, 'b> Handler<'a> {
/// Build the application CLI definition.
pub fn build() -> App<'a, 'b> {
App::new(APP_NAME)
.version(APP_VERSION)
.author(APP_AUTHOR)
.about(APP_ABOUT)
.subcommand(CmdUpload::build().display_order(1))
}
/// Parse CLI arguments.
pub fn parse() -> Handler<'a> {
// Build the application CLI definition, get the matches
Handler {
matches: Handler::build().get_matches(),
}
}
/// Get the upload sub command, if matched.
pub fn upload(&'a self) -> Option<CmdUpload<'a>> {
CmdUpload::parse(&self.matches)
}
}