Upgrade to clap 3.1
This commit is contained in:
parent
1d33870aa6
commit
0d2bf91676
5 changed files with 58 additions and 60 deletions
|
@ -22,7 +22,6 @@ rpassword = "5"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
structopt = "0.3"
|
clap = { version = "3.1", features = ["derive"] }
|
||||||
clap = "2.33"
|
|
||||||
env_logger = "0.8"
|
env_logger = "0.8"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|
|
@ -1,31 +1,31 @@
|
||||||
// SPDX-FileCopyrightText: 2021 Heiko Schaefer <heiko@schaefer.name>
|
// SPDX-FileCopyrightText: 2021 Heiko Schaefer <heiko@schaefer.name>
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
use clap::AppSettings;
|
use clap::{AppSettings, Parser};
|
||||||
use structopt::StructOpt;
|
|
||||||
|
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[structopt(name = "opgpcard",
|
#[clap(
|
||||||
author = "Heiko Schäfer <heiko@schaefer.name>",
|
name = "opgpcard",
|
||||||
global_settings(& [AppSettings::VersionlessSubcommands,
|
author = "Heiko Schäfer <heiko@schaefer.name>",
|
||||||
AppSettings::DisableHelpSubcommand, AppSettings::DeriveDisplayOrder]),
|
disable_help_subcommand(true),
|
||||||
about = "A tool for managing OpenPGP cards."
|
global_setting(AppSettings::DeriveDisplayOrder),
|
||||||
|
about = "A tool for managing OpenPGP cards."
|
||||||
)]
|
)]
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
#[structopt(name = "card ident", short = "c", long = "card")]
|
#[clap(name = "card ident", short = 'c', long = "card")]
|
||||||
pub ident: String,
|
pub ident: String,
|
||||||
|
|
||||||
#[structopt(subcommand)]
|
#[clap(subcommand)]
|
||||||
pub cmd: Command,
|
pub cmd: Command,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
SetUserPin {},
|
SetUserPin {},
|
||||||
SetAdminPin {},
|
SetAdminPin {},
|
||||||
SetResetCode {},
|
SetResetCode {},
|
||||||
ResetUserPin {
|
ResetUserPin {
|
||||||
#[structopt(name = "reset as admin", short = "a", long = "admin")]
|
#[clap(name = "reset as admin", short = 'a', long = "admin")]
|
||||||
admin: bool,
|
admin: bool,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use structopt::StructOpt;
|
use clap::Parser;
|
||||||
|
|
||||||
use openpgp_card::{Error, OpenPgp, StatusBytes};
|
use openpgp_card::{Error, OpenPgp, StatusBytes};
|
||||||
use openpgp_card_pcsc::PcscBackend;
|
use openpgp_card_pcsc::PcscBackend;
|
||||||
|
@ -13,7 +13,7 @@ mod cli;
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
env_logger::init();
|
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 card = PcscBackend::open_by_ident(&cli.ident, None)?;
|
||||||
let mut pgp = OpenPgp::new(&mut card);
|
let mut pgp = OpenPgp::new(&mut card);
|
||||||
|
|
|
@ -1,85 +1,88 @@
|
||||||
// SPDX-FileCopyrightText: 2021 Heiko Schaefer <heiko@schaefer.name>
|
// SPDX-FileCopyrightText: 2021 Heiko Schaefer <heiko@schaefer.name>
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
use clap::AppSettings;
|
use clap::{AppSettings, Parser};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use structopt::StructOpt;
|
|
||||||
|
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[structopt(name = "opgpcard",
|
#[clap(
|
||||||
author = "Heiko Schäfer <heiko@schaefer.name>",
|
name = "opgpcard",
|
||||||
global_settings(& [AppSettings::VersionlessSubcommands,
|
author = "Heiko Schäfer <heiko@schaefer.name>",
|
||||||
AppSettings::DisableHelpSubcommand, AppSettings::DeriveDisplayOrder]),
|
disable_help_subcommand(true),
|
||||||
about = "A tool for managing OpenPGP cards."
|
global_setting(AppSettings::DeriveDisplayOrder),
|
||||||
|
about = "A tool for managing OpenPGP cards."
|
||||||
)]
|
)]
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
#[structopt(subcommand)]
|
#[clap(subcommand)]
|
||||||
pub cmd: Command,
|
pub cmd: Command,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
List {},
|
List {},
|
||||||
Status {
|
Status {
|
||||||
#[structopt(name = "card ident", short = "c", long = "card")]
|
#[clap(name = "card ident", short = 'c', long = "card")]
|
||||||
ident: Option<String>,
|
ident: Option<String>,
|
||||||
|
|
||||||
#[structopt(name = "verbose", short = "v", long = "verbose")]
|
#[clap(name = "verbose", short = 'v', long = "verbose")]
|
||||||
verbose: bool,
|
verbose: bool,
|
||||||
},
|
},
|
||||||
FactoryReset {
|
FactoryReset {
|
||||||
#[structopt(name = "card ident", short = "c", long = "card")]
|
#[clap(name = "card ident", short = 'c', long = "card")]
|
||||||
ident: String,
|
ident: String,
|
||||||
},
|
},
|
||||||
SetIdentity {
|
SetIdentity {
|
||||||
#[structopt(name = "card ident", short = "c", long = "card")]
|
#[clap(name = "card ident", short = 'c', long = "card")]
|
||||||
ident: String,
|
ident: String,
|
||||||
|
|
||||||
#[structopt(name = "identity")]
|
#[clap(name = "identity")]
|
||||||
id: u8,
|
id: u8,
|
||||||
},
|
},
|
||||||
Admin {
|
Admin {
|
||||||
#[structopt(name = "card ident", short = "c", long = "card")]
|
#[clap(name = "card ident", short = 'c', long = "card")]
|
||||||
ident: String,
|
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<PathBuf>,
|
admin_pin: Option<PathBuf>,
|
||||||
|
|
||||||
#[structopt(subcommand)]
|
#[clap(subcommand)]
|
||||||
cmd: AdminCommand,
|
cmd: AdminCommand,
|
||||||
},
|
},
|
||||||
Decrypt {
|
Decrypt {
|
||||||
#[structopt(name = "card ident", short = "c", long = "card")]
|
#[clap(name = "card ident", short = 'c', long = "card")]
|
||||||
ident: String,
|
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<PathBuf>,
|
user_pin: Option<PathBuf>,
|
||||||
|
|
||||||
#[structopt(name = "recipient-cert-file", short = "r", long = "recipient-cert")]
|
#[clap(name = "recipient-cert-file", short = 'r', long = "recipient-cert")]
|
||||||
cert_file: PathBuf,
|
cert_file: PathBuf,
|
||||||
|
|
||||||
#[structopt(about = "Input file (stdin if unset)", name = "input")]
|
/// Input file (stdin if unset)
|
||||||
|
#[clap(name = "input")]
|
||||||
input: Option<PathBuf>,
|
input: Option<PathBuf>,
|
||||||
},
|
},
|
||||||
Sign {
|
Sign {
|
||||||
#[structopt(name = "card ident", short = "c", long = "card")]
|
#[clap(name = "card ident", short = 'c', long = "card")]
|
||||||
ident: String,
|
ident: String,
|
||||||
|
|
||||||
#[structopt(name = "User PIN file", short = "p", long = "user-pin")]
|
/// User PIN file
|
||||||
|
#[clap(short = 'p', long = "user-pin")]
|
||||||
user_pin: Option<PathBuf>,
|
user_pin: Option<PathBuf>,
|
||||||
|
|
||||||
#[structopt(name = "detached", short = "d", long = "detached")]
|
#[clap(name = "detached", short = 'd', long = "detached")]
|
||||||
detached: bool,
|
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,
|
cert_file: PathBuf,
|
||||||
|
|
||||||
#[structopt(about = "Input file (stdin if unset)", name = "input")]
|
/// Input file (stdin if unset)
|
||||||
|
#[clap(name = "input")]
|
||||||
input: Option<PathBuf>,
|
input: Option<PathBuf>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
pub enum AdminCommand {
|
pub enum AdminCommand {
|
||||||
/// Set name
|
/// Set name
|
||||||
Name { name: String },
|
Name { name: String },
|
||||||
|
@ -94,13 +97,13 @@ pub enum AdminCommand {
|
||||||
Import {
|
Import {
|
||||||
keyfile: PathBuf,
|
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<String>,
|
sig_fp: Option<String>,
|
||||||
|
|
||||||
#[structopt(name = "Decryption key fingerprint", short = "d", long = "dec-fp")]
|
#[clap(name = "Decryption key fingerprint", short = 'd', long = "dec-fp")]
|
||||||
dec_fp: Option<String>,
|
dec_fp: Option<String>,
|
||||||
|
|
||||||
#[structopt(name = "Authentication key fingerprint", short = "a", long = "auth-fp")]
|
#[clap(name = "Authentication key fingerprint", short = 'a', long = "auth-fp")]
|
||||||
auth_fp: Option<String>,
|
auth_fp: Option<String>,
|
||||||
},
|
},
|
||||||
/// Generate a Key.
|
/// Generate a Key.
|
||||||
|
@ -108,25 +111,21 @@ pub enum AdminCommand {
|
||||||
/// A signing key is always created, decryption and authentication keys
|
/// A signing key is always created, decryption and authentication keys
|
||||||
/// are optional.
|
/// are optional.
|
||||||
Generate {
|
Generate {
|
||||||
#[structopt(name = "User PIN file", short = "p", long = "user-pin")]
|
#[clap(name = "User PIN file", short = 'p', long = "user-pin")]
|
||||||
user_pin: Option<PathBuf>,
|
user_pin: Option<PathBuf>,
|
||||||
|
|
||||||
#[structopt(
|
/// Output file (stdout if unset)
|
||||||
about = "Output file (stdout if unset)",
|
#[clap(name = "output", long = "output", short = 'o')]
|
||||||
name = "output",
|
|
||||||
long = "output",
|
|
||||||
short = "o"
|
|
||||||
)]
|
|
||||||
output: Option<PathBuf>,
|
output: Option<PathBuf>,
|
||||||
|
|
||||||
#[structopt(long = "no-decrypt")]
|
#[clap(long = "no-decrypt")]
|
||||||
no_decrypt: bool,
|
no_decrypt: bool,
|
||||||
|
|
||||||
#[structopt(long = "no-auth")]
|
#[clap(long = "no-auth")]
|
||||||
no_auth: bool,
|
no_auth: bool,
|
||||||
|
|
||||||
#[structopt(about = "Algorithm \
|
/// Algorithm (rsa2048|rsa3072|rsa4096|nistp256|nistp384|nistp521|25519)
|
||||||
(rsa2048|rsa3072|rsa4096|nistp256|nistp384|nistp521|25519)")]
|
#[clap()]
|
||||||
algo: Option<String>,
|
algo: Option<String>,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
// SPDX-License-Identifier: MIT OR Apache-2.0
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
|
use clap::Parser;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use structopt::StructOpt;
|
|
||||||
|
|
||||||
use sequoia_openpgp::parse::{stream::DecryptorBuilder, Parse};
|
use sequoia_openpgp::parse::{stream::DecryptorBuilder, Parse};
|
||||||
use sequoia_openpgp::policy::StandardPolicy;
|
use sequoia_openpgp::policy::StandardPolicy;
|
||||||
|
@ -26,7 +26,7 @@ mod util;
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
let cli = cli::Cli::from_args();
|
let cli = cli::Cli::parse();
|
||||||
|
|
||||||
match cli.cmd {
|
match cli.cmd {
|
||||||
cli::Command::List {} => {
|
cli::Command::List {} => {
|
||||||
|
|
Loading…
Reference in a new issue