summaryrefslogtreecommitdiffstats
path: root/sq
diff options
context:
space:
mode:
authorLars Wirzenius <liw@sequoia-pgp.org>2022-07-06 11:09:38 +0300
committerLars Wirzenius <liw@sequoia-pgp.org>2022-07-15 15:49:16 +0300
commit499b6d549774c09991884fdb6709e12193f0be5e (patch)
treea4d4523676314c3a30c4c48f3977aeaa86b0e696 /sq
parent360d6ddb605088da78da67a6f63126c8d149595a (diff)
sq: add global options --output-format and --output-version
Nothing implements these yet, this is preparation for future changes. Sponsored-by: NLnet Foundation; NGI Assure
Diffstat (limited to 'sq')
-rw-r--r--sq/src/sq-usage.rs9
-rw-r--r--sq/src/sq.rs11
-rw-r--r--sq/src/sq_cli.rs14
3 files changed, 34 insertions, 0 deletions
diff --git a/sq/src/sq-usage.rs b/sq/src/sq-usage.rs
index 8afcd1e2..d1bb1b74 100644
--- a/sq/src/sq-usage.rs
+++ b/sq/src/sq-usage.rs
@@ -32,6 +32,15 @@
//! validating signatures. Signatures that have unknown notations with
//! the critical bit set are considered invalid.
//!
+//! --output-format <FORMAT>
+//! Produces output in FORMAT, if possible
+//!
+//! [default: human-readable]
+//! [possible values: human-readable, json]
+//!
+//! --output-version <VERSION>
+//! Produces output variant VERSION
+//!
//! -V, --version
//! Print version information
//!
diff --git a/sq/src/sq.rs b/sq/src/sq.rs
index 7457e23e..441ce89f 100644
--- a/sq/src/sq.rs
+++ b/sq/src/sq.rs
@@ -4,6 +4,7 @@ use anyhow::Context as _;
use std::fs::OpenOptions;
use std::io;
use std::path::{Path, PathBuf};
+use std::str::FromStr;
use std::time::Duration;
use chrono::{DateTime, offset::Utc};
use itertools::Itertools;
@@ -336,6 +337,8 @@ fn emit_unstable_cli_warning() {
#[derive(Clone)]
pub struct Config<'a> {
force: bool,
+ output_format: OutputFormat,
+ output_version: Option<OutputVersion>,
policy: P<'a>,
/// Have we emitted the warning yet?
unstable_cli_warning_emitted: bool,
@@ -396,9 +399,17 @@ fn main() -> Result<()> {
policy.good_critical_notations(&known_notations);
let force = c.force;
+ let output_format = OutputFormat::from_str(&c.output_format)?;
+ let output_version = if let Some(v) = c.output_version {
+ Some(OutputVersion::from_str(&v)?)
+ } else {
+ None
+ };
let mut config = Config {
force,
+ output_format,
+ output_version,
policy: policy.clone(),
unstable_cli_warning_emitted: false,
};
diff --git a/sq/src/sq_cli.rs b/sq/src/sq_cli.rs
index 0e745570..0c106745 100644
--- a/sq/src/sq_cli.rs
+++ b/sq/src/sq_cli.rs
@@ -60,6 +60,20 @@ pub struct SqCommand {
)]
pub force: bool,
#[clap(
+ long = "output-format",
+ value_name = "FORMAT",
+ possible_values = ["human-readable", "json"],
+ default_value = "human-readable",
+ help = "Produces output in FORMAT, if possible",
+ )]
+ pub output_format: String,
+ #[clap(
+ long = "output-version",
+ value_name = "VERSION",
+ help = "Produces output variant VERSION",
+ )]
+ pub output_version: Option<String>,
+ #[clap(
long = "known-notation",
value_name = "NOTATION",
multiple_occurrences = true,