diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2018-03-26 12:14:06 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2018-03-26 15:15:24 +0200 |
commit | a1b1ccd7d85f453e16cc11b38884759df306d4fa (patch) | |
tree | 59b78836733206a01feb88cbbfb00255627545b8 /tool | |
parent | 90cb7835e69f654eca0f1c3a56cd3cbd53517d93 (diff) |
tool: Move command line parser to its own file.
Diffstat (limited to 'tool')
-rw-r--r-- | tool/src/cli.rs | 152 | ||||
-rw-r--r-- | tool/src/main.rs | 153 |
2 files changed, 155 insertions, 150 deletions
diff --git a/tool/src/cli.rs b/tool/src/cli.rs new file mode 100644 index 00000000..ee627d27 --- /dev/null +++ b/tool/src/cli.rs @@ -0,0 +1,152 @@ +use clap::{App, Arg, SubCommand, AppSettings}; + +pub fn build() -> App<'static, 'static> { + App::new("sq") + .version("0.1.0") + .about("Sequoia is an implementation of OpenPGP. This is a command-line frontend.") + .setting(AppSettings::ArgRequiredElseHelp) + .arg(Arg::with_name("domain").value_name("DOMAIN") + .long("domain") + .short("d") + .help("Sets the domain to use")) + .arg(Arg::with_name("policy").value_name("NETWORK-POLICY") + .long("policy") + .short("p") + .help("Sets the network policy to use")) + .subcommand(SubCommand::with_name("enarmor") + .about("Applies ASCII Armor to a file") + .arg(Arg::with_name("input").value_name("FILE") + .long("input") + .short("i") + .help("Sets the input file to use")) + .arg(Arg::with_name("output").value_name("FILE") + .long("output") + .short("o") + .help("Sets the output file to use"))) + .subcommand(SubCommand::with_name("dearmor") + .about("Removes ASCII Armor from a file") + .arg(Arg::with_name("input").value_name("FILE") + .long("input") + .short("i") + .help("Sets the input file to use")) + .arg(Arg::with_name("output").value_name("FILE") + .long("output") + .short("o") + .help("Sets the output file to use"))) + .subcommand(SubCommand::with_name("dump") + .about("Lists OpenPGP packets") + .arg(Arg::with_name("input").value_name("FILE") + .long("input") + .short("i") + .help("Sets the input file to use")) + .arg(Arg::with_name("output").value_name("FILE") + .long("output") + .short("o") + .help("Sets the output file to use")) + .arg(Arg::with_name("dearmor") + .long("dearmor") + .short("A") + .help("Remove ASCII Armor from input"))) + .subcommand(SubCommand::with_name("keyserver") + .about("Interacts with keyservers") + .arg(Arg::with_name("server").value_name("URI") + .long("server") + .short("s") + .help("Sets the keyserver to use")) + .subcommand(SubCommand::with_name("get") + .about("Retrieves a key") + .arg(Arg::with_name("output").value_name("FILE") + .long("output") + .short("o") + .help("Sets the output file to use")) + .arg(Arg::with_name("armor") + .long("armor") + .short("A") + .help("Write armored data to file")) + .arg(Arg::with_name("keyid").value_name("KEYID") + .required(true) + .help("ID of the key to retrieve"))) + .subcommand(SubCommand::with_name("send") + .about("Sends a key") + .arg(Arg::with_name("input").value_name("FILE") + .long("input") + .short("i") + .help("Sets the input file to use")) + .arg(Arg::with_name("dearmor") + .long("dearmor") + .short("A") + .help("Remove ASCII Armor from input")))) + .subcommand(SubCommand::with_name("store") + .about("Interacts with key stores") + .arg(Arg::with_name("name").value_name("NAME") + .required(true) + .help("Name of the store")) + .subcommand(SubCommand::with_name("list") + .about("Lists keys in the store")) + .subcommand(SubCommand::with_name("add") + .about("Add a key identified by fingerprint") + .arg(Arg::with_name("label").value_name("LABEL") + .required(true) + .help("Label to use")) + .arg(Arg::with_name("fingerprint").value_name("FINGERPRINT") + .required(true) + .help("Key to add"))) + .subcommand(SubCommand::with_name("import") + .about("Imports a key") + .arg(Arg::with_name("label").value_name("LABEL") + .required(true) + .help("Label to use")) + .arg(Arg::with_name("input").value_name("FILE") + .long("input") + .short("i") + .help("Sets the input file to use")) + .arg(Arg::with_name("dearmor") + .long("dearmor") + .short("A") + .help("Remove ASCII Armor from input"))) + .subcommand(SubCommand::with_name("export") + .about("Exports a key") + .arg(Arg::with_name("label").value_name("LABEL") + .required(true) + .help("Label to use")) + .arg(Arg::with_name("output").value_name("FILE") + .long("output") + .short("o") + .help("Sets the output file to use")) + .arg(Arg::with_name("armor") + .long("armor") + .short("A") + .help("Write armored data to file"))) + .subcommand(SubCommand::with_name("delete") + .about("Deletes bindings or stores") + .arg(Arg::with_name("the-store") + .long("the-store") + .help("Delete the whole store")) + .arg(Arg::with_name("label") + .value_name("LABEL") + .help("Delete binding with this label"))) + .subcommand(SubCommand::with_name("stats") + .about("Get stats for the given label") + .arg(Arg::with_name("label").value_name("LABEL") + .required(true) + .help("Label to use"))) + .subcommand(SubCommand::with_name("log") + .about("Lists the keystore log") + .arg(Arg::with_name("label") + .value_name("LABEL") + .help("List messages related to this label")))) + .subcommand(SubCommand::with_name("list") + .about("Lists key stores and known keys") + .subcommand(SubCommand::with_name("stores") + .about("Lists key stores") + .arg(Arg::with_name("prefix").value_name("PREFIX") + .help("List only stores with the given domain prefix"))) + .subcommand(SubCommand::with_name("bindings") + .about("Lists all bindings in all key stores") + .arg(Arg::with_name("prefix").value_name("PREFIX") + .help("List only bindings from stores with the given domain prefix"))) + .subcommand(SubCommand::with_name("keys") + .about("Lists all keys in the common key pool")) + .subcommand(SubCommand::with_name("log") + .about("Lists the server log"))) +} diff --git a/tool/src/main.rs b/tool/src/main.rs index 01bbddb4..32593287 100644 --- a/tool/src/main.rs +++ b/tool/src/main.rs @@ -6,7 +6,6 @@ extern crate failure; extern crate prettytable; extern crate time; -use clap::{Arg, App, SubCommand, AppSettings}; use failure::ResultExt; use prettytable::Table; use prettytable::cell::Cell; @@ -26,6 +25,8 @@ use sequoia_core::{Context, NetworkPolicy}; use sequoia_net::KeyServer; use sequoia_store::{Store, LogIter}; +mod cli; + fn open_or_stdin(f: Option<&str>) -> Result<Box<io::Read>, failure::Error> { match f { Some(f) => Ok(Box::new(File::open(f)?)), @@ -41,155 +42,7 @@ fn create_or_stdout(f: Option<&str>) -> Result<Box<io::Write>, failure::Error> { } fn real_main() -> Result<(), failure::Error> { - let matches = App::new("sq") - .version("0.1.0") - .about("Sequoia is an implementation of OpenPGP. This is a command-line frontend.") - .setting(AppSettings::ArgRequiredElseHelp) - .arg(Arg::with_name("domain").value_name("DOMAIN") - .long("domain") - .short("d") - .help("Sets the domain to use")) - .arg(Arg::with_name("policy").value_name("NETWORK-POLICY") - .long("policy") - .short("p") - .help("Sets the network policy to use")) - .subcommand(SubCommand::with_name("enarmor") - .about("Applies ASCII Armor to a file") - .arg(Arg::with_name("input").value_name("FILE") - .long("input") - .short("i") - .help("Sets the input file to use")) - .arg(Arg::with_name("output").value_name("FILE") - .long("output") - .short("o") - .help("Sets the output file to use"))) - .subcommand(SubCommand::with_name("dearmor") - .about("Removes ASCII Armor from a file") - .arg(Arg::with_name("input").value_name("FILE") - .long("input") - .short("i") - .help("Sets the input file to use")) - .arg(Arg::with_name("output").value_name("FILE") - .long("output") - .short("o") - .help("Sets the output file to use"))) - .subcommand(SubCommand::with_name("dump") - .about("Lists OpenPGP packets") - .arg(Arg::with_name("input").value_name("FILE") - .long("input") - .short("i") - .help("Sets the input file to use")) - .arg(Arg::with_name("output").value_name("FILE") - .long("output") - .short("o") - .help("Sets the output file to use")) - .arg(Arg::with_name("dearmor") - .long("dearmor") - .short("A") - .help("Remove ASCII Armor from input"))) - .subcommand(SubCommand::with_name("keyserver") - .about("Interacts with keyservers") - .arg(Arg::with_name("server").value_name("URI") - .long("server") - .short("s") - .help("Sets the keyserver to use")) - .subcommand(SubCommand::with_name("get") - .about("Retrieves a key") - .arg(Arg::with_name("output").value_name("FILE") - .long("output") - .short("o") - .help("Sets the output file to use")) - .arg(Arg::with_name("armor") - .long("armor") - .short("A") - .help("Write armored data to file")) - .arg(Arg::with_name("keyid").value_name("KEYID") - .required(true) - .help("ID of the key to retrieve"))) - .subcommand(SubCommand::with_name("send") - .about("Sends a key") - .arg(Arg::with_name("input").value_name("FILE") - .long("input") - .short("i") - .help("Sets the input file to use")) - .arg(Arg::with_name("dearmor") - .long("dearmor") - .short("A") - .help("Remove ASCII Armor from input")))) - .subcommand(SubCommand::with_name("store") - .about("Interacts with key stores") - .arg(Arg::with_name("name").value_name("NAME") - .required(true) - .help("Name of the store")) - .subcommand(SubCommand::with_name("list") - .about("Lists keys in the store")) - .subcommand(SubCommand::with_name("add") - .about("Add a key identified by fingerprint") - .arg(Arg::with_name("label").value_name("LABEL") - .required(true) - .help("Label to use")) - .arg(Arg::with_name("fingerprint").value_name("FINGERPRINT") - .required(true) - .help("Key to add"))) - .subcommand(SubCommand::with_name("import") - .about("Imports a key") - .arg(Arg::with_name("label").value_name("LABEL") - .required(true) - .help("Label to use")) - .arg(Arg::with_name("input").value_name("FILE") - .long("input") - .short("i") - .help("Sets the input file to use")) - .arg(Arg::with_name("dearmor") - .long("dearmor") - .short("A") - .help("Remove ASCII Armor from input"))) - .subcommand(SubCommand::with_name("export") - .about("Exports a key") - .arg(Arg::with_name("label").value_name("LABEL") - .required(true) - .help("Label to use")) - .arg(Arg::with_name("output").value_name("FILE") - .long("output") - .short("o") - .help("Sets the output file to use")) - .arg(Arg::with_name("armor") - .long("armor") - .short("A") - .help("Write armored data to file"))) - .subcommand(SubCommand::with_name("delete") - .about("Deletes bindings or stores") - .arg(Arg::with_name("the-store") - .long("the-store") - .help("Delete the whole store")) - .arg(Arg::with_name("label") - .value_name("LABEL") - .help("Delete binding with this label"))) - .subcommand(SubCommand::with_name("stats") - .about("Get stats for the given label") - .arg(Arg::with_name("label").value_name("LABEL") - .required(true) - .help("Label to use"))) - .subcommand(SubCommand::with_name("log") - .about("Lists the keystore log") - .arg(Arg::with_name("label") - .value_name("LABEL") - .help("List messages related to this label")))) - .subcommand(SubCommand::with_name("list") - .about("Lists key stores and known keys") - .subcommand(SubCommand::with_name("stores") - .about("Lists key stores") - .arg(Arg::with_name("prefix").value_name("PREFIX") - .help("List only stores with the given domain prefix"))) - .subcommand(SubCommand::with_name("bindings") - .about("Lists all bindings in all key stores") - .arg(Arg::with_name("prefix").value_name("PREFIX") - .help("List only bindings from stores with the given domain prefix"))) - .subcommand(SubCommand::with_name("keys") - .about("Lists all keys in the common key pool")) - .subcommand(SubCommand::with_name("log") - .about("Lists the server log"))) - .get_matches(); + let matches = cli::build().get_matches(); let policy = match matches.value_of("policy") { None => NetworkPolicy::Encrypted, |