summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNora Widdecke <nora@sequoia-pgp.org>2022-05-13 00:06:14 +0200
committerNora Widdecke <nora@sequoia-pgp.org>2022-05-13 00:52:40 +0200
commit9164286525fbe5449012f09fcdcff97f278ff51e (patch)
tree63b562c1cba30b1d113eeb2175dfe03664a574bb
parent6794c21c845233eef5b14ae945342fe089285a08 (diff)
add a subcommandsnora/clap3_mix
I tried to have both subcommands in one Enum, that derives Parser, but that adds another layer of subcommands for which I haven't found a workaround.
-rw-r--r--sq/src/sq-usage.rs30
-rw-r--r--sq/src/sq.rs8
-rw-r--r--sq/src/sq_cli.rs23
3 files changed, 60 insertions, 1 deletions
diff --git a/sq/src/sq-usage.rs b/sq/src/sq-usage.rs
index 66ba9d38..1977f77d 100644
--- a/sq/src/sq-usage.rs
+++ b/sq/src/sq-usage.rs
@@ -66,6 +66,10 @@
//! Low-level packet manipulation
//! revoke
//! Generates revocation certificates
+//! baz
+//! baz help text
+//! foo
+//! foo help text
//! help
//! Print this message or the help of the given subcommand(s)
//! ```
@@ -2038,6 +2042,32 @@
//!
//! For more information try --help
//! ```
+//!
+//! ## Subcommand baz
+//!
+//! ```text
+//! baz help text
+//!
+//! USAGE:
+//! sq baz --quux <QUUX>
+//!
+//! OPTIONS:
+//! -h, --help Print help information
+//! -q, --quux <QUUX> quux argument
+//! ```
+//!
+//! ## Subcommand foo
+//!
+//! ```text
+//! foo help text
+//!
+//! USAGE:
+//! sq foo [OPTIONS]
+//!
+//! OPTIONS:
+//! -b, --bar bar flag
+//! -h, --help Print help information
+//! ```
#![doc(html_favicon_url = "https://docs.sequoia-pgp.org/favicon.png")]
#![doc(html_logo_url = "https://docs.sequoia-pgp.org/logo.svg")]
diff --git a/sq/src/sq.rs b/sq/src/sq.rs
index bb481065..326958b0 100644
--- a/sq/src/sq.rs
+++ b/sq/src/sq.rs
@@ -706,6 +706,14 @@ fn main() -> Result<()> {
commands::certify::certify(config, m)?;
},
+ Some(("foo", m)) => {
+ use clap::FromArgMatches;
+ let fc = sq_cli::FooCommand::from_arg_matches(m)?;
+ println!("hello foo :), {:?}", fc)
+ }
+ Some((_, m)) => {
+ println!("hello :), {:?}", m)
+ }
_ => unreachable!(),
}
diff --git a/sq/src/sq_cli.rs b/sq/src/sq_cli.rs
index 4c9d3846..2a8b037b 100644
--- a/sq/src/sq_cli.rs
+++ b/sq/src/sq_cli.rs
@@ -1,6 +1,7 @@
/// Command-line parser for sq.
use clap::{Command, Arg, ArgGroup};
+use clap::{Parser, CommandFactory};
pub fn build() -> Command<'static> {
configure(Command::new("sq"),
@@ -1923,7 +1924,27 @@ $ sq autocrypt encode-sender --prefer-encrypt mutual juliet.pgp
attribute"))
)
)
- };
+ }
+ .subcommand(FooCommand::command())
+ .subcommand(BazCommand::command());
app
}
+
+#[derive(Parser, Debug)]
+#[clap(name = "foo")]
+#[clap(about="foo help text")]
+pub struct FooCommand {
+ /// bar flag
+ #[clap(short, long)]
+ bar: bool,
+}
+
+#[derive(Parser, Debug)]
+#[clap(name = "baz")]
+#[clap(about="baz help text")]
+pub struct BazCommand {
+ /// quux argument
+ #[clap(short, long)]
+ quux: String,
+}