Files
plist-tool/src/args.rs
2021-05-23 01:14:20 +08:00

39 lines
1.3 KiB
Rust

use clap::{ArgMatches, App, Arg};
pub enum PlistFormat {
Xml,
Binary,
}
pub struct ParsedArgs {
pub in_file: String,
pub format: PlistFormat,
pub out_file: Option<String>,
}
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."),
},
out_file: matches.value_of("out").map(ToString::to_string),
}
}
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("out").short("o").long("out").takes_value(true).help("Output plist file"))
.arg(Arg::with_name("FILE").required(true).index(1).help("Input plist file name"))
.get_matches()
}