summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Wirzenius <liw@sequoia-pgp.org>2022-07-19 12:39:32 +0300
committerLars Wirzenius <liw@sequoia-pgp.org>2022-07-19 14:07:51 +0300
commitff7f174ce286427f2d6ef1c984adaba4ad7f1bf1 (patch)
tree20b08957fa538fae14187246cb8b6313b64af5f5
parentf771d80fd81f1e71dbe010b82654e436ba31fc26 (diff)
sq: allow choosing output format and version via the environment
SQ_OUTPUT_FORMAT and SQ_OUTPUT_VERSION will be obeyed unless the corresponding options are used. Sponsored-by: NLnet Foundation; NGI Assure
-rw-r--r--sq/Cargo.toml2
-rw-r--r--sq/sq-subplot.md8
-rw-r--r--sq/src/sq-usage.rs3
-rw-r--r--sq/src/sq_cli.rs2
4 files changed, 14 insertions, 1 deletions
diff --git a/sq/Cargo.toml b/sq/Cargo.toml
index 9413e8d0..d2adf70c 100644
--- a/sq/Cargo.toml
+++ b/sq/Cargo.toml
@@ -32,7 +32,7 @@ sequoia-autocrypt = { path = "../autocrypt", version = "0.24", default-features
sequoia-net = { path = "../net", version = "0.25", default-features = false }
anyhow = "1.0.18"
chrono = "0.4.10"
-clap = { version = "3", features = ["derive", "wrap_help"] }
+clap = { version = "3", features = ["derive", "env", "wrap_help"] }
itertools = "0.10"
tempfile = "3.1"
term_size = "0.3"
diff --git a/sq/sq-subplot.md b/sq/sq-subplot.md
index dbab79bf..a9184528 100644
--- a/sq/sq-subplot.md
+++ b/sq/sq-subplot.md
@@ -838,6 +838,8 @@ given an installed sq
when I run sq key generate --userid Alice --export alice.pgp
when I try to run sq --output-version=9999 keyring list alice.pgp
then command fails
+when I try to run env SQ_OUTPUT_VERSION=9999 sq keyring list alice.pgp
+then command fails
~~~
### Choose too-new output minor version for keyring listing
@@ -893,6 +895,12 @@ then I remember the fingerprint as BOB_FINGERPRINT
when I run sq keyring join alice.pgp bob.pgp -o ring.pgp
when I run sq --output-format=json keyring list ring.pgp
then stdout, as JSON, matches pattern keyring-list-pattern.json
+
+when I run env SQ_OUTPUT_FORMAT=json sq keyring list ring.pgp
+then stdout, as JSON, matches pattern keyring-list-pattern.json
+
+when I run env SQ_OUTPUT_FORMAT=human-readable sq --output-format=json keyring list ring.pgp
+then stdout, as JSON, matches pattern keyring-list-pattern.json
~~~
~~~{#keyring-list-pattern.json .file .json .numberLines}
diff --git a/sq/src/sq-usage.rs b/sq/src/sq-usage.rs
index d1bb1b74..186cd0f7 100644
--- a/sq/src/sq-usage.rs
+++ b/sq/src/sq-usage.rs
@@ -35,11 +35,14 @@
//! --output-format <FORMAT>
//! Produces output in FORMAT, if possible
//!
+//! [env: SQ_OUTPUT_FORMAT=]
//! [default: human-readable]
//! [possible values: human-readable, json]
//!
//! --output-version <VERSION>
//! Produces output variant VERSION
+//!
+//! [env: SQ_OUTPUT_VERSION=]
//!
//! -V, --version
//! Print version information
diff --git a/sq/src/sq_cli.rs b/sq/src/sq_cli.rs
index 0c106745..f477e9d9 100644
--- a/sq/src/sq_cli.rs
+++ b/sq/src/sq_cli.rs
@@ -64,12 +64,14 @@ pub struct SqCommand {
value_name = "FORMAT",
possible_values = ["human-readable", "json"],
default_value = "human-readable",
+ env = "SQ_OUTPUT_FORMAT",
help = "Produces output in FORMAT, if possible",
)]
pub output_format: String,
#[clap(
long = "output-version",
value_name = "VERSION",
+ env = "SQ_OUTPUT_VERSION",
help = "Produces output variant VERSION",
)]
pub output_version: Option<String>,