feat: works
This commit is contained in:
35
src/args.rs
Normal file
35
src/args.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use clap::{ArgMatches, App, Arg};
|
||||
|
||||
pub enum PlistFormat {
|
||||
Xml,
|
||||
Binary,
|
||||
}
|
||||
|
||||
pub struct ParsedArgs {
|
||||
pub in_file: String,
|
||||
pub format: PlistFormat,
|
||||
}
|
||||
|
||||
pub fn parse_args(matches: ArgMatches<'static>) -> ParsedArgs {
|
||||
ParsedArgs {
|
||||
in_file: matches.value_of("FILE").unwrap().to_string(),
|
||||
format: match matches.value_of("format") {
|
||||
Some("xml") => PlistFormat::Xml,
|
||||
Some("bin") | Some("binary") => PlistFormat::Binary,
|
||||
_ => failure_and_exit!("Plist format error."),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_args_matches() -> ArgMatches<'static> {
|
||||
App::new(env!("CARGO_PKG_NAME"))
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
.author(env!("CARGO_PKG_AUTHORS"))
|
||||
.about(env!("CARGO_PKG_DESCRIPTION"))
|
||||
.arg(Arg::with_name("format").short("f").long("format").takes_value(true)
|
||||
.default_value("xml")
|
||||
.possible_values(&["xml", "binary", "bin"])
|
||||
.help("Output plist format")
|
||||
).arg(Arg::with_name("FILE").required(true).index(1).help("plist file name"))
|
||||
.get_matches()
|
||||
}
|
||||
Reference in New Issue
Block a user