summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNora Widdecke <nora@sequoia-pgp.org>2022-06-09 09:01:13 +0200
committerNora Widdecke <nora@sequoia-pgp.org>2022-06-09 09:07:52 +0200
commit830c2fc62c3ac0767a36ede7330f93b9539b9b67 (patch)
tree761ffedf12e870721c2665dc98baac1735eac365
parentaf7f50c49316c92cc08c6521af0f7328a397dea6 (diff)
sq: Fix autocrypt conditional compilation.
-rw-r--r--Cargo.lock1
-rw-r--r--sq/Cargo.toml2
-rw-r--r--sq/build.rs1
-rw-r--r--sq/src/sq_cli.rs50
4 files changed, 25 insertions, 29 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 9a8df1a9..37f78aa7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2698,6 +2698,7 @@ dependencies = [
"anyhow",
"assert_cmd",
"buffered-reader",
+ "cfg-if",
"chrono",
"clap 3.1.17",
"clap_complete",
diff --git a/sq/Cargo.toml b/sq/Cargo.toml
index 47f121ea..85a2ea48 100644
--- a/sq/Cargo.toml
+++ b/sq/Cargo.toml
@@ -31,6 +31,7 @@ sequoia-openpgp = { path = "../openpgp", version = "1.1", default-features = fal
sequoia-autocrypt = { path = "../autocrypt", version = "0.24", default-features = false, optional = true }
sequoia-net = { path = "../net", version = "0.24", default-features = false }
anyhow = "1.0.18"
+cfg-if = "1"
chrono = "0.4.10"
clap = { version = "3", features = ["derive", "wrap_help"] }
itertools = "0.10"
@@ -44,6 +45,7 @@ clap = "3"
clap_complete = "3"
sequoia-openpgp = { path = "../openpgp", version = "1.0.0", default-features = false }
subplot-build = "0.4.0"
+cfg-if = "1"
[dev-dependencies]
subplotlib = "0.4.1"
diff --git a/sq/build.rs b/sq/build.rs
index d276dc71..59c11f17 100644
--- a/sq/build.rs
+++ b/sq/build.rs
@@ -19,7 +19,6 @@ fn main() {
let mut sq = sq_cli::configure(
clap::Command::new("sq").term_width(80),
- cfg!(feature = "autocrypt"),
);
let mut main = fs::File::create("src/sq-usage.rs").unwrap();
dump_help(&mut main,
diff --git a/sq/src/sq_cli.rs b/sq/src/sq_cli.rs
index 5947a272..0e50d26f 100644
--- a/sq/src/sq_cli.rs
+++ b/sq/src/sq_cli.rs
@@ -3,9 +3,7 @@ use clap::{Arg, ArgGroup, Command, ArgEnum, Args, Subcommand};
use clap::{CommandFactory, Parser};
pub fn build() -> Command<'static> {
- configure(Command::new("sq"),
- cfg!(feature = "autocrypt"),
- )
+ configure(Command::new("sq"))
}
// TODO: use clap_derive for the whole CLI
@@ -20,8 +18,7 @@ pub fn build() -> Command<'static> {
/// - Armor (5xx)
/// - Inspection & packet manipulation (6xx)
pub fn configure(
- app: Command<'static>,
- feature_autocrypt: bool,
+ app: Command<'static>
) -> Command<'static> {
let version = Box::leak(
format!("{} (sequoia-openpgp {}, using {})",
@@ -64,29 +61,26 @@ to refer to OpenPGP keys that do contain secrets.
Signatures that have unknown notations with the \
critical bit set are considered invalid."));
- let app = if ! feature_autocrypt {
- // Without Autocrypt support.
- app
- } else {
- // With Autocrypt support.
- app.subcommand(autocrypt::AutocryptCommand::command())
- }
- .subcommand(ArmorCommand::command())
- .subcommand(DearmorCommand::command())
- .subcommand(SignCommand::command())
- .subcommand(VerifyCommand::command())
- .subcommand(WkdCommand::command())
- .subcommand(KeyserverCommand::command())
- .subcommand(RevokeCommand::command())
- .subcommand(PacketCommand::command())
- .subcommand(CertifyCommand::command())
- .subcommand(KeyringCommand::command())
- .subcommand(KeyCommand::command())
- .subcommand(InspectCommand::command())
- .subcommand(EncryptCommand::command())
- .subcommand(DecryptCommand::command());
-
- app
+ cfg_if::cfg_if! {
+ if #[cfg(feature = "autocrypt")] {
+ let app = app.subcommand(autocrypt::AutocryptCommand::command());
+ }
+ };
+
+ app.subcommand(ArmorCommand::command())
+ .subcommand(DearmorCommand::command())
+ .subcommand(SignCommand::command())
+ .subcommand(VerifyCommand::command())
+ .subcommand(WkdCommand::command())
+ .subcommand(KeyserverCommand::command())
+ .subcommand(RevokeCommand::command())
+ .subcommand(PacketCommand::command())
+ .subcommand(CertifyCommand::command())
+ .subcommand(KeyringCommand::command())
+ .subcommand(KeyCommand::command())
+ .subcommand(InspectCommand::command())
+ .subcommand(EncryptCommand::command())
+ .subcommand(DecryptCommand::command())
}
#[derive(Debug, Args)]