Implement sq version, drop --version, move output-version there.
This commit is contained in:
parent
5e2c6da79c
commit
4a236421da
@ -109,9 +109,9 @@ then we can't expect anything else to work either.
|
||||
|
||||
~~~scenario
|
||||
given an installed sq
|
||||
when I run sq --version
|
||||
when I run sq version
|
||||
then exit code is 0
|
||||
then stdout matches regex ^sq \d+\.\d+\.\d+ .*$
|
||||
then stderr matches regex ^sq \d+\.\d+\.\d+
|
||||
~~~
|
||||
|
||||
# Key management: `sq key`
|
||||
|
@ -94,10 +94,11 @@ pub mod key;
|
||||
pub mod keyring;
|
||||
pub mod network;
|
||||
pub mod output;
|
||||
pub mod pki;
|
||||
pub mod sign;
|
||||
pub mod toolbox;
|
||||
pub mod verify;
|
||||
pub mod pki;
|
||||
pub mod version;
|
||||
|
||||
pub mod types;
|
||||
|
||||
@ -156,6 +157,7 @@ to refer to OpenPGP keys that do contain secrets.
|
||||
subcommand_required = true,
|
||||
arg_required_else_help = true,
|
||||
disable_colored_help = true,
|
||||
disable_version_flag = true,
|
||||
)]
|
||||
pub struct SqCommand {
|
||||
#[clap(
|
||||
@ -358,5 +360,5 @@ pub enum SqSubcommands {
|
||||
|
||||
Toolbox(toolbox::Command),
|
||||
|
||||
OutputVersions(output::Command),
|
||||
Version(version::Command),
|
||||
}
|
||||
|
@ -2,21 +2,9 @@ use std::fmt;
|
||||
use std::str::FromStr;
|
||||
|
||||
use anyhow::{anyhow, Result};
|
||||
use clap::{ValueEnum, Parser};
|
||||
use clap::ValueEnum;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(
|
||||
name = "output-versions",
|
||||
display_order = 110,
|
||||
about = "List supported output versions",
|
||||
)]
|
||||
pub struct Command {
|
||||
/// List only the default output version.
|
||||
#[clap(long)]
|
||||
pub default: bool,
|
||||
}
|
||||
|
||||
/// What output format to prefer, when there's an option?
|
||||
#[derive(ValueEnum, Clone, Copy, Debug)]
|
||||
pub enum OutputFormat {
|
||||
|
36
src/cli/version.rs
Normal file
36
src/cli/version.rs
Normal file
@ -0,0 +1,36 @@
|
||||
//! Command-line parser for `sq inspect`.
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[clap(
|
||||
name = "version",
|
||||
about = "Detailed version and output version information",
|
||||
long_about =
|
||||
"Detailed version and output version information
|
||||
|
||||
With no further options, this command lists the version of `sq`, the
|
||||
version of the underlying OpenPGP implementation `sequoia-openpgp`,
|
||||
and which cryptographic library is used.
|
||||
|
||||
This command can also be used to query the output format versions for
|
||||
the machine-readable output of various subcommands, and the default
|
||||
output format versions.
|
||||
|
||||
",
|
||||
)]
|
||||
pub struct Command {
|
||||
/// List the default output version.
|
||||
#[clap(
|
||||
long,
|
||||
conflicts_with = "output_versions",
|
||||
)]
|
||||
pub default_output_version: bool,
|
||||
|
||||
/// List all the supported output versions.
|
||||
#[clap(
|
||||
long,
|
||||
conflicts_with = "default_output_version",
|
||||
)]
|
||||
pub output_versions: bool,
|
||||
}
|
@ -37,9 +37,10 @@ pub mod inspect;
|
||||
pub mod key;
|
||||
pub mod keyring;
|
||||
pub mod net;
|
||||
pub mod pki;
|
||||
pub mod toolbox;
|
||||
pub mod verify;
|
||||
pub mod pki;
|
||||
pub mod version;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum GetKeysOptions {
|
||||
|
27
src/commands/version.rs
Normal file
27
src/commands/version.rs
Normal file
@ -0,0 +1,27 @@
|
||||
//! Detailed version and output version information.
|
||||
|
||||
use crate::{
|
||||
Config,
|
||||
Result,
|
||||
cli::version,
|
||||
output,
|
||||
};
|
||||
|
||||
pub fn dispatch(_config: Config, c: version::Command)
|
||||
-> Result<()>
|
||||
{
|
||||
if c.default_output_version {
|
||||
wprintln!("{}", output::DEFAULT_OUTPUT_VERSION);
|
||||
} else if c.output_versions {
|
||||
for v in output::OUTPUT_VERSIONS {
|
||||
println!("{}", v);
|
||||
}
|
||||
} else {
|
||||
wprintln!("sq {}", env!("CARGO_PKG_VERSION"));
|
||||
wprintln!("using sequoia-openpgp {}", sequoia_openpgp::VERSION);
|
||||
wprintln!("with cryptographic backend {}",
|
||||
sequoia_openpgp::crypto::backend());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
12
src/sq.rs
12
src/sq.rs
@ -1095,16 +1095,6 @@ 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) => {
|
||||
commands::decrypt::dispatch(config, command)?
|
||||
},
|
||||
@ -1143,6 +1133,8 @@ fn main() -> Result<()> {
|
||||
|
||||
SqSubcommands::Network(command) =>
|
||||
commands::net::dispatch(config, command)?,
|
||||
SqSubcommands::Version(command) =>
|
||||
commands::version::dispatch(config, command)?,
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
Loading…
x
Reference in New Issue
Block a user