mirror of
https://github.com/timvisee/ffsend.git
synced 2025-10-03 17:49:15 +02:00
Improve CLI argument handling for subcommand use
This commit is contained in:
parent
188b0cb2e1
commit
fb7fd69400
7 changed files with 110 additions and 45 deletions
35
src/cmd/handler.rs
Normal file
35
src/cmd/handler.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
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)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue