diff options
author | Lars Wirzenius <liw@sequoia-pgp.org> | 2022-07-20 18:57:52 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@sequoia-pgp.org> | 2022-07-20 20:15:38 +0300 |
commit | 178519e257c8b64a6a99cd8c10c94727ed42127e (patch) | |
tree | 6139625f3fcd805c76174dab2895a41b51a393cd /sq | |
parent | c50f20f3553b835ec526f86e40c800d802c088be (diff) |
sq: add command output-versions
This allows the user to query what output versions are available and
what is the current default one.
Sponsored-by: NLnet Foundation; NGI Assure
Diffstat (limited to 'sq')
-rw-r--r-- | sq/sq-usage.md | 23 | ||||
-rw-r--r-- | sq/src/output.rs | 14 | ||||
-rw-r--r-- | sq/src/sq.rs | 10 | ||||
-rw-r--r-- | sq/src/sq_cli.rs | 21 |
4 files changed, 64 insertions, 4 deletions
diff --git a/sq/sq-usage.md b/sq/sq-usage.md index 85e8d7c2..927c66a3 100644 --- a/sq/sq-usage.md +++ b/sq/sq-usage.md @@ -32,7 +32,10 @@ OPTIONS: [possible values: human-readable, json] --output-version <VERSION> - Produces output variant VERSION + Produces output variant VERSION, such as 0.0.0. The default is the + newest version. The output version is separate from the version of + the sq program. To see the current supported versions, use + output-versions subcommand. [env: SQ_OUTPUT_VERSION=] @@ -80,6 +83,8 @@ SUBCOMMANDS: Generates revocation certificates help Print this message or the help of the given subcommand(s) + output-versions + List supported output versions ``` ## Subcommand sq encrypt @@ -2140,3 +2145,19 @@ OPTIONS: Chooses keys valid at the specified time and sets the revocation certificate's creation time ``` + +## Subcommand sq output versions + +```text +List supported output versions + +USAGE: + sq output-versions [OPTIONS] + +OPTIONS: + --default + List only the default output version + + -h, --help + Print help information +``` diff --git a/sq/src/output.rs b/sq/src/output.rs index eb7f5f55..811bc07d 100644 --- a/sq/src/output.rs +++ b/sq/src/output.rs @@ -13,6 +13,9 @@ use serde::Serialize; pub use keyring::ListItem as KeyringListItem; pub use wkd::WkdUrlVariant; +pub const DEFAULT_OUTPUT_VERSION: OutputVersion = OutputVersion::new(0, 0, 0); +pub const OUTPUT_VERSIONS: &[OutputVersion] = &[OutputVersion::new(0, 0, 0)]; + /// What output format to prefer, when there's an option? #[derive(Clone)] pub enum OutputFormat { @@ -98,6 +101,14 @@ impl fmt::Display for OutputVersion { } } +impl PartialEq<OutputVersion> for &OutputVersion { + fn eq(&self, other: &OutputVersion) -> bool { + self.major == other.major && + self.minor == other.minor && + self.patch == other.patch + } +} + fn parse_ints(s: &str) -> Result<Vec<usize>> { let mut ints = vec![]; let mut v = s; @@ -134,10 +145,9 @@ pub enum Model { } impl Model { - const DEFAULT_VERSION: OutputVersion = OutputVersion::new(0, 0, 0); fn version(v: Option<OutputVersion>) -> OutputVersion { - v.unwrap_or(Self::DEFAULT_VERSION) + v.unwrap_or(DEFAULT_OUTPUT_VERSION) } /// Create a model for the output of `sq wkd url` and `sq wkd diff --git a/sq/src/sq.rs b/sq/src/sq.rs index bf761f41..e5ba9860 100644 --- a/sq/src/sq.rs +++ b/sq/src/sq.rs @@ -418,6 +418,16 @@ fn main() -> Result<()> { }; match c.subcommand { + SqSubcommands::OutputVersions(command) => { + if command.default { + println!("{}", output::DEFAULT_OUTPUT_VERSION); + } else { + for v in output::OUTPUT_VERSIONS { + println!("{}", v); + } + } + } + SqSubcommands::Decrypt(command) => { let mut input = open_or_stdin(command.io.input.as_deref())?; diff --git a/sq/src/sq_cli.rs b/sq/src/sq_cli.rs index 123f428c..aff78c71 100644 --- a/sq/src/sq_cli.rs +++ b/sq/src/sq_cli.rs @@ -64,7 +64,12 @@ pub struct SqCommand { long = "output-version", value_name = "VERSION", env = "SQ_OUTPUT_VERSION", - help = "Produces output variant VERSION", + help = "Produces output variant VERSION.", + long_help = "Produces output variant VERSION, such as 0.0.0. \ + The default is the newest version. The output version \ + is separate from the version of the sq program. To see \ + the current supported versions, use output-versions \ + subcommand." )] pub output_version: Option<String>, #[clap( @@ -117,6 +122,8 @@ pub enum SqSubcommands { Packet(PacketCommand), Revoke(RevokeCommand), + + OutputVersions(OutputVersionsCommand), } use chrono::{offset::Utc, DateTime}; @@ -2807,6 +2814,18 @@ impl<'a> std::fmt::Display for CliSessionKeyDisplay<'a> { } } +#[derive(Parser, Debug)] +#[clap( + name = "output-versions", + display_order = 110, + about = "List supported output versions", +)] +pub struct OutputVersionsCommand { + /// List only the default output version. + #[clap(long)] + pub default: bool, +} + #[cfg(feature = "autocrypt")] pub mod autocrypt { use super::*; |