diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2019-03-13 16:42:24 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2019-03-13 17:24:42 +0100 |
commit | 6ca0c166e047eec89623b7edead32eb6aeeba6fa (patch) | |
tree | 3b54a381a9e9a9f9a2b6e1b28c479d7b8bc0fb56 /tool | |
parent | 9d09e668fa9ff7f86ec385993044e7946301bf60 (diff) |
sq: New subcommand 'packet'.
- This moves the packet-related subcommands below 'sq packet'.
Diffstat (limited to 'tool')
-rw-r--r-- | tool/src/sq-usage.rs | 67 | ||||
-rw-r--r-- | tool/src/sq.rs | 49 | ||||
-rw-r--r-- | tool/src/sq_cli.rs | 55 |
3 files changed, 99 insertions, 72 deletions
diff --git a/tool/src/sq-usage.rs b/tool/src/sq-usage.rs index 6981e439..18c9d452 100644 --- a/tool/src/sq-usage.rs +++ b/tool/src/sq-usage.rs @@ -28,13 +28,12 @@ //! keyserver Interacts with keyservers //! autocrypt Autocrypt support //! dearmor Removes ASCII Armor from a file -//! dump Lists OpenPGP packets //! enarmor Applies ASCII Armor to a file //! help Prints this message or the help of the given subcommand(s) //! inspect Inspects a sequence of OpenPGP packets //! key Manipulates keys //! list Lists key stores and known keys -//! split Splits a message into OpenPGP packets +//! packet OpenPGP Packet manipulation //! ``` //! //! ## Subcommand decrypt @@ -382,27 +381,6 @@ //! <FILE> Sets the input file to use //! ``` //! -//! ## Subcommand dump -//! -//! ```text -//! Lists OpenPGP packets -//! -//! USAGE: -//! sq dump [FLAGS] [OPTIONS] [FILE] -//! -//! FLAGS: -//! -h, --help Prints help information -//! -x, --hex Print a hexdump -//! --mpis Print MPIs -//! -V, --version Prints version information -//! -//! OPTIONS: -//! -o, --output <FILE> Sets the output file to use -//! -//! ARGS: -//! <FILE> Sets the input file to use -//! ``` -//! //! ## Subcommand enarmor //! //! ```text @@ -562,13 +540,52 @@ //! <PREFIX> List only stores with the given domain prefix //! ``` //! -//! ## Subcommand split +//! ## Subcommand packet +//! +//! ```text +//! OpenPGP Packet manipulation +//! +//! USAGE: +//! sq packet [SUBCOMMAND] +//! +//! FLAGS: +//! -h, --help Prints help information +//! -V, --version Prints version information +//! +//! SUBCOMMANDS: +//! dump Lists OpenPGP packets +//! help Prints this message or the help of the given subcommand(s) +//! split Splits a message into OpenPGP packets +//! ``` +//! +//! ### Subcommand packet dump +//! +//! ```text +//! Lists OpenPGP packets +//! +//! USAGE: +//! sq packet dump [FLAGS] [OPTIONS] [FILE] +//! +//! FLAGS: +//! -h, --help Prints help information +//! -x, --hex Print a hexdump +//! --mpis Print MPIs +//! -V, --version Prints version information +//! +//! OPTIONS: +//! -o, --output <FILE> Sets the output file to use +//! +//! ARGS: +//! <FILE> Sets the input file to use +//! ``` +//! +//! ### Subcommand packet split //! //! ```text //! Splits a message into OpenPGP packets //! //! USAGE: -//! sq split [OPTIONS] [FILE] +//! sq packet split [OPTIONS] [FILE] //! //! FLAGS: //! -h, --help Prints help information diff --git a/tool/src/sq.rs b/tool/src/sq.rs index 3706844f..ead02aa3 100644 --- a/tool/src/sq.rs +++ b/tool/src/sq.rs @@ -217,34 +217,39 @@ fn real_main() -> Result<(), failure::Error> { } }, - ("dump", Some(m)) => { - let mut input = open_or_stdin(m.value_of("input"))?; - let mut output = create_or_stdout(m.value_of("output"), force)?; - commands::dump(&mut input, &mut output, - m.is_present("mpis"), m.is_present("hex"))?; - }, ("inspect", Some(m)) => { let mut output = create_or_stdout(m.value_of("output"), force)?; commands::inspect(m, &mut output)?; }, - ("split", Some(m)) => { - let mut input = open_or_stdin(m.value_of("input"))?; - let prefix = + + ("packet", Some(m)) => match m.subcommand() { + ("dump", Some(m)) => { + let mut input = open_or_stdin(m.value_of("input"))?; + let mut output = create_or_stdout(m.value_of("output"), force)?; + commands::dump(&mut input, &mut output, + m.is_present("mpis"), m.is_present("hex"))?; + }, + ("split", Some(m)) => { + let mut input = open_or_stdin(m.value_of("input"))?; + let prefix = // The prefix is either specified explicitly... - m.value_of("prefix").map(|p| p.to_owned()) - .unwrap_or( - // ... or we derive it from the input file... - m.value_of("input").and_then(|i| { - let p = PathBuf::from(i); - // (but only use the filename) - p.file_name().map(|f| String::from(f.to_string_lossy())) - }) - // ... or we use a generic prefix... - .unwrap_or(String::from("output")) - // ... finally, add a hyphen to the derived prefix. - + "-"); - commands::split(&mut input, &prefix)?; + m.value_of("prefix").map(|p| p.to_owned()) + .unwrap_or( + // ... or we derive it from the input file... + m.value_of("input").and_then(|i| { + let p = PathBuf::from(i); + // (but only use the filename) + p.file_name().map(|f| String::from(f.to_string_lossy())) + }) + // ... or we use a generic prefix... + .unwrap_or(String::from("output")) + // ... finally, add a hyphen to the derived prefix. + + "-"); + commands::split(&mut input, &prefix)?; + }, + _ => unreachable!(), }, + ("keyserver", Some(m)) => { let mut ks = if let Some(uri) = m.value_of("server") { KeyServer::new(&ctx, &uri) diff --git a/tool/src/sq_cli.rs b/tool/src/sq_cli.rs index 0da389fd..70d87b95 100644 --- a/tool/src/sq_cli.rs +++ b/tool/src/sq_cli.rs @@ -201,21 +201,6 @@ pub fn build() -> App<'static, 'static> { .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") - .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("mpis") - .long("mpis") - .help("Print MPIs")) - .arg(Arg::with_name("hex") - .long("hex") - .short("x") - .help("Print a hexdump"))) .subcommand(SubCommand::with_name("inspect") .about("Inspects a sequence of OpenPGP packets") .arg(Arg::with_name("input").value_name("FILE") @@ -226,16 +211,7 @@ pub fn build() -> App<'static, 'static> { .arg(Arg::with_name("certifications") .long("certifications") .help("Print third-party certifications"))) - .subcommand(SubCommand::with_name("split") - .about("Splits a message into OpenPGP packets") - .arg(Arg::with_name("input").value_name("FILE") - .help("Sets the input file to use")) - .arg(Arg::with_name("prefix").value_name("FILE") - .long("prefix") - .short("p") - .help("Sets the prefix to use for output files \ - (defaults to the input filename with a dash, \ - or 'output')"))) + .subcommand(SubCommand::with_name("keyserver") .display_order(40) .about("Interacts with keyservers") @@ -385,4 +361,33 @@ pub fn build() -> App<'static, 'static> { .help("Sets the output file for the revocation \ certificate. Default is <OUTFILE>.rev, \ mandatory if OUTFILE is '-'.")))) + + .subcommand(SubCommand::with_name("packet") + .about("OpenPGP Packet manipulation") + .setting(AppSettings::ArgRequiredElseHelp) + .subcommand(SubCommand::with_name("dump") + .about("Lists OpenPGP packets") + .arg(Arg::with_name("input").value_name("FILE") + .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("mpis") + .long("mpis") + .help("Print MPIs")) + .arg(Arg::with_name("hex") + .long("hex") + .short("x") + .help("Print a hexdump"))) + .subcommand(SubCommand::with_name("split") + .about("Splits a message into OpenPGP packets") + .arg(Arg::with_name("input").value_name("FILE") + .help("Sets the input file to use")) + .arg(Arg::with_name("prefix").value_name("FILE") + .long("prefix") + .short("p") + .help("Sets the prefix to use for output files \ + (defaults to the input filename with a dash, \ + or 'output')")))) } |