diff --git a/tools/Cargo.toml b/tools/Cargo.toml index 0374b46..4fbe3ea 100644 --- a/tools/Cargo.toml +++ b/tools/Cargo.toml @@ -22,7 +22,6 @@ rpassword = "5" chrono = "0.4" anyhow = "1" thiserror = "1" -structopt = "0.3" -clap = "2.33" +clap = { version = "3.1", features = ["derive"] } env_logger = "0.8" log = "0.4" diff --git a/tools/src/bin/opgpcard-pin/cli.rs b/tools/src/bin/opgpcard-pin/cli.rs index 33f84fd..6a3625b 100644 --- a/tools/src/bin/opgpcard-pin/cli.rs +++ b/tools/src/bin/opgpcard-pin/cli.rs @@ -1,31 +1,31 @@ // SPDX-FileCopyrightText: 2021 Heiko Schaefer // SPDX-License-Identifier: MIT OR Apache-2.0 -use clap::AppSettings; -use structopt::StructOpt; +use clap::{AppSettings, Parser}; -#[derive(StructOpt, Debug)] -#[structopt(name = "opgpcard", -author = "Heiko Schäfer ", -global_settings(& [AppSettings::VersionlessSubcommands, -AppSettings::DisableHelpSubcommand, AppSettings::DeriveDisplayOrder]), -about = "A tool for managing OpenPGP cards." +#[derive(Parser, Debug)] +#[clap( + name = "opgpcard", + author = "Heiko Schäfer ", + disable_help_subcommand(true), + global_setting(AppSettings::DeriveDisplayOrder), + about = "A tool for managing OpenPGP cards." )] pub struct Cli { - #[structopt(name = "card ident", short = "c", long = "card")] + #[clap(name = "card ident", short = 'c', long = "card")] pub ident: String, - #[structopt(subcommand)] + #[clap(subcommand)] pub cmd: Command, } -#[derive(StructOpt, Debug)] +#[derive(Parser, Debug)] pub enum Command { SetUserPin {}, SetAdminPin {}, SetResetCode {}, ResetUserPin { - #[structopt(name = "reset as admin", short = "a", long = "admin")] + #[clap(name = "reset as admin", short = 'a', long = "admin")] admin: bool, }, } diff --git a/tools/src/bin/opgpcard-pin/main.rs b/tools/src/bin/opgpcard-pin/main.rs index 34c1845..e7a5550 100644 --- a/tools/src/bin/opgpcard-pin/main.rs +++ b/tools/src/bin/opgpcard-pin/main.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use anyhow::Result; -use structopt::StructOpt; +use clap::Parser; use openpgp_card::{Error, OpenPgp, StatusBytes}; use openpgp_card_pcsc::PcscBackend; @@ -13,7 +13,7 @@ mod cli; fn main() -> Result<(), Box> { env_logger::init(); - let cli = cli::Cli::from_args(); + let cli = cli::Cli::parse(); let mut card = PcscBackend::open_by_ident(&cli.ident, None)?; let mut pgp = OpenPgp::new(&mut card); diff --git a/tools/src/bin/opgpcard/cli.rs b/tools/src/bin/opgpcard/cli.rs index b9fb0d5..1261bf4 100644 --- a/tools/src/bin/opgpcard/cli.rs +++ b/tools/src/bin/opgpcard/cli.rs @@ -1,85 +1,88 @@ // SPDX-FileCopyrightText: 2021 Heiko Schaefer // SPDX-License-Identifier: MIT OR Apache-2.0 -use clap::AppSettings; +use clap::{AppSettings, Parser}; use std::path::PathBuf; -use structopt::StructOpt; -#[derive(StructOpt, Debug)] -#[structopt(name = "opgpcard", -author = "Heiko Schäfer ", -global_settings(& [AppSettings::VersionlessSubcommands, -AppSettings::DisableHelpSubcommand, AppSettings::DeriveDisplayOrder]), -about = "A tool for managing OpenPGP cards." +#[derive(Parser, Debug)] +#[clap( + name = "opgpcard", + author = "Heiko Schäfer ", + disable_help_subcommand(true), + global_setting(AppSettings::DeriveDisplayOrder), + about = "A tool for managing OpenPGP cards." )] pub struct Cli { - #[structopt(subcommand)] + #[clap(subcommand)] pub cmd: Command, } -#[derive(StructOpt, Debug)] +#[derive(Parser, Debug)] pub enum Command { List {}, Status { - #[structopt(name = "card ident", short = "c", long = "card")] + #[clap(name = "card ident", short = 'c', long = "card")] ident: Option, - #[structopt(name = "verbose", short = "v", long = "verbose")] + #[clap(name = "verbose", short = 'v', long = "verbose")] verbose: bool, }, FactoryReset { - #[structopt(name = "card ident", short = "c", long = "card")] + #[clap(name = "card ident", short = 'c', long = "card")] ident: String, }, SetIdentity { - #[structopt(name = "card ident", short = "c", long = "card")] + #[clap(name = "card ident", short = 'c', long = "card")] ident: String, - #[structopt(name = "identity")] + #[clap(name = "identity")] id: u8, }, Admin { - #[structopt(name = "card ident", short = "c", long = "card")] + #[clap(name = "card ident", short = 'c', long = "card")] ident: String, - #[structopt(name = "Admin PIN file", short = "P", long = "admin-pin")] + #[clap(name = "Admin PIN file", short = 'P', long = "admin-pin")] admin_pin: Option, - #[structopt(subcommand)] + #[clap(subcommand)] cmd: AdminCommand, }, Decrypt { - #[structopt(name = "card ident", short = "c", long = "card")] + #[clap(name = "card ident", short = 'c', long = "card")] ident: String, - #[structopt(name = "User PIN file", short = "p", long = "user-pin")] + #[clap(name = "User PIN file", short = 'p', long = "user-pin")] user_pin: Option, - #[structopt(name = "recipient-cert-file", short = "r", long = "recipient-cert")] + #[clap(name = "recipient-cert-file", short = 'r', long = "recipient-cert")] cert_file: PathBuf, - #[structopt(about = "Input file (stdin if unset)", name = "input")] + /// Input file (stdin if unset) + #[clap(name = "input")] input: Option, }, Sign { - #[structopt(name = "card ident", short = "c", long = "card")] + #[clap(name = "card ident", short = 'c', long = "card")] ident: String, - #[structopt(name = "User PIN file", short = "p", long = "user-pin")] + /// User PIN file + #[clap(short = 'p', long = "user-pin")] user_pin: Option, - #[structopt(name = "detached", short = "d", long = "detached")] + #[clap(name = "detached", short = 'd', long = "detached")] detached: bool, - #[structopt(name = "signer-cert-file", short = "s", long = "signer-cert")] + #[clap(name = "signer-cert-file", short = 's', long = "signer-cert")] cert_file: PathBuf, - #[structopt(about = "Input file (stdin if unset)", name = "input")] + /// Input file (stdin if unset) + #[clap(name = "input")] input: Option, }, } -#[derive(StructOpt, Debug)] +#[derive(Parser, Debug)] pub enum AdminCommand { /// Set name Name { name: String }, @@ -94,13 +97,13 @@ pub enum AdminCommand { Import { keyfile: PathBuf, - #[structopt(name = "Signature key fingerprint", short = "s", long = "sig-fp")] + #[clap(name = "Signature key fingerprint", short = 's', long = "sig-fp")] sig_fp: Option, - #[structopt(name = "Decryption key fingerprint", short = "d", long = "dec-fp")] + #[clap(name = "Decryption key fingerprint", short = 'd', long = "dec-fp")] dec_fp: Option, - #[structopt(name = "Authentication key fingerprint", short = "a", long = "auth-fp")] + #[clap(name = "Authentication key fingerprint", short = 'a', long = "auth-fp")] auth_fp: Option, }, /// Generate a Key. @@ -108,25 +111,21 @@ pub enum AdminCommand { /// A signing key is always created, decryption and authentication keys /// are optional. Generate { - #[structopt(name = "User PIN file", short = "p", long = "user-pin")] + #[clap(name = "User PIN file", short = 'p', long = "user-pin")] user_pin: Option, - #[structopt( - about = "Output file (stdout if unset)", - name = "output", - long = "output", - short = "o" - )] + /// Output file (stdout if unset) + #[clap(name = "output", long = "output", short = 'o')] output: Option, - #[structopt(long = "no-decrypt")] + #[clap(long = "no-decrypt")] no_decrypt: bool, - #[structopt(long = "no-auth")] + #[clap(long = "no-auth")] no_auth: bool, - #[structopt(about = "Algorithm \ - (rsa2048|rsa3072|rsa4096|nistp256|nistp384|nistp521|25519)")] + /// Algorithm (rsa2048|rsa3072|rsa4096|nistp256|nistp384|nistp521|25519) + #[clap()] algo: Option, }, } diff --git a/tools/src/bin/opgpcard/main.rs b/tools/src/bin/opgpcard/main.rs index 5e1b051..488e468 100644 --- a/tools/src/bin/opgpcard/main.rs +++ b/tools/src/bin/opgpcard/main.rs @@ -2,8 +2,8 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 use anyhow::{anyhow, Result}; +use clap::Parser; use std::path::{Path, PathBuf}; -use structopt::StructOpt; use sequoia_openpgp::parse::{stream::DecryptorBuilder, Parse}; use sequoia_openpgp::policy::StandardPolicy; @@ -26,7 +26,7 @@ mod util; fn main() -> Result<(), Box> { env_logger::init(); - let cli = cli::Cli::from_args(); + let cli = cli::Cli::parse(); match cli.cmd { cli::Command::List {} => {