Add more help output, re-organize commands

This commit is contained in:
Heiko Schaefer 2022-04-21 20:06:07 +02:00
parent 3442bd265d
commit c275bfc7dd
No known key found for this signature in database
GPG key ID: 4A849A1904CCBD7D

View file

@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2021 Heiko Schaefer <heiko@schaefer.name> // SPDX-FileCopyrightText: 2021-2022 Heiko Schaefer <heiko@schaefer.name>
// SPDX-License-Identifier: MIT OR Apache-2.0 // SPDX-License-Identifier: MIT OR Apache-2.0
use clap::{AppSettings, Parser}; use clap::{AppSettings, Parser};
@ -8,9 +8,10 @@ use std::path::PathBuf;
#[clap( #[clap(
name = "opgpcard", name = "opgpcard",
author = "Heiko Schäfer <heiko@schaefer.name>", author = "Heiko Schäfer <heiko@schaefer.name>",
version,
disable_help_subcommand(true), disable_help_subcommand(true),
global_setting(AppSettings::DeriveDisplayOrder), global_setting(AppSettings::DeriveDisplayOrder),
about = "A tool for managing OpenPGP cards." about = "A tool for inspecting and configuring OpenPGP cards."
)] )]
pub struct Cli { pub struct Cli {
#[clap(subcommand)] #[clap(subcommand)]
@ -19,7 +20,10 @@ pub struct Cli {
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
pub enum Command { pub enum Command {
/// Enumerate available OpenPGP cards
List {}, List {},
/// Show information about the data on a card
Status { Status {
#[clap(name = "card ident", short = 'c', long = "card")] #[clap(name = "card ident", short = 'c', long = "card")]
ident: Option<String>, ident: Option<String>,
@ -27,14 +31,20 @@ pub enum Command {
#[clap(name = "verbose", short = 'v', long = "verbose")] #[clap(name = "verbose", short = 'v', long = "verbose")]
verbose: bool, verbose: bool,
}, },
/// Show technical details about a card
Info { Info {
#[clap(name = "card ident", short = 'c', long = "card")] #[clap(name = "card ident", short = 'c', long = "card")]
ident: Option<String>, ident: Option<String>,
}, },
/// Display a card's authentication key as an SSH public key
Ssh { Ssh {
#[clap(name = "card ident", short = 'c', long = "card")] #[clap(name = "card ident", short = 'c', long = "card")]
ident: Option<String>, ident: Option<String>,
}, },
/// Export the key data on a card as an OpenPGP public key
Pubkey { Pubkey {
#[clap(name = "card ident", short = 'c', long = "card")] #[clap(name = "card ident", short = 'c', long = "card")]
ident: Option<String>, ident: Option<String>,
@ -42,17 +52,8 @@ pub enum Command {
#[clap(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>,
}, },
FactoryReset {
#[clap(name = "card ident", short = 'c', long = "card")]
ident: String,
},
SetIdentity {
#[clap(name = "card ident", short = 'c', long = "card")]
ident: String,
#[clap(name = "identity")] /// Administer data on a card (including keys and metadata)
id: u8,
},
Admin { Admin {
#[clap(name = "card ident", short = 'c', long = "card")] #[clap(name = "card ident", short = 'c', long = "card")]
ident: String, ident: String,
@ -63,6 +64,8 @@ pub enum Command {
#[clap(subcommand)] #[clap(subcommand)]
cmd: AdminCommand, cmd: AdminCommand,
}, },
/// PIN management (change PINs, reset blocked PINs)
Pin { Pin {
#[clap(name = "card ident", short = 'c', long = "card")] #[clap(name = "card ident", short = 'c', long = "card")]
ident: String, ident: String,
@ -70,6 +73,8 @@ pub enum Command {
#[clap(subcommand)] #[clap(subcommand)]
cmd: PinCommand, cmd: PinCommand,
}, },
/// Decrypt data using a card
Decrypt { Decrypt {
#[clap(name = "card ident", short = 'c', long = "card")] #[clap(name = "card ident", short = 'c', long = "card")]
ident: String, ident: String,
@ -84,6 +89,8 @@ pub enum Command {
#[clap(name = "input")] #[clap(name = "input")]
input: Option<PathBuf>, input: Option<PathBuf>,
}, },
/// Sign data using a card
Sign { Sign {
#[clap(name = "card ident", short = 'c', long = "card")] #[clap(name = "card ident", short = 'c', long = "card")]
ident: String, ident: String,
@ -102,14 +109,29 @@ pub enum Command {
#[clap(name = "input")] #[clap(name = "input")]
input: Option<PathBuf>, input: Option<PathBuf>,
}, },
/// Completely reset a card (deletes all data, including the keys on the card!)
FactoryReset {
#[clap(name = "card ident", short = 'c', long = "card")]
ident: String,
},
/// Change identity (applies only to Nitrokey Start)
SetIdentity {
#[clap(name = "card ident", short = 'c', long = "card")]
ident: String,
#[clap(name = "identity")]
id: u8,
},
} }
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
pub enum AdminCommand { pub enum AdminCommand {
/// Set name /// Set cardholder name
Name { name: String }, Name { name: String },
/// Set URL /// Set cardholder URL
Url { url: String }, Url { url: String },
/// Import a Key. /// Import a Key.
@ -128,6 +150,7 @@ pub enum AdminCommand {
#[clap(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.
/// ///
/// A signing key is always created, decryption and authentication keys /// A signing key is always created, decryption and authentication keys
@ -172,7 +195,7 @@ pub enum PinCommand {
admin_pin_new: Option<PathBuf>, admin_pin_new: Option<PathBuf>,
}, },
/// Reset User PIN with admin PIN /// Reset User PIN with Admin PIN
ResetUser { ResetUser {
#[clap(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>,
@ -190,9 +213,9 @@ pub enum PinCommand {
reset_code: Option<PathBuf>, reset_code: Option<PathBuf>,
}, },
/// Reset User PIN with 'resetting code' /// Reset User PIN with 'Resetting Code'
ResetUserRc { ResetUserRc {
#[clap(name = "Resetting code file", short = 'r', long = "reset-code")] #[clap(name = "Resetting Code file", short = 'r', long = "reset-code")]
reset_code: Option<PathBuf>, reset_code: Option<PathBuf>,
#[clap(name = "User PIN file new", short = 'p', long = "user-pin-new")] #[clap(name = "User PIN file new", short = 'p', long = "user-pin-new")]