cli: rename 'list' command to 'readers'; improve usage
There are going to be several `list` commands (e.g. `yubikey keys list`) so this is a confusing name. If we need more than one `readers` subcommand we can change this to be `readers list` eventually. Separately (in what probably should've been its own commit, mea culpa) this adds slightly better usage.
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ application providing general-purpose public-key signing and encryption
|
|||||||
with hardware-backed private keys for RSA (2048/1024) and ECC (P-256/P-384)
|
with hardware-backed private keys for RSA (2048/1024) and ECC (P-256/P-384)
|
||||||
algorithms (e.g, PKCS#1v1.5, ECDSA)
|
algorithms (e.g, PKCS#1v1.5, ECDSA)
|
||||||
"""
|
"""
|
||||||
authors = ["Tony Arcieri <bascule@gmail.com>", "Yubico AB"]
|
authors = ["Tony Arcieri <tony@iqlusion.io>", "Yubico AB"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "BSD-2-Clause"
|
license = "BSD-2-Clause"
|
||||||
repository = "https://github.com/iqlusioninc/yubikey-piv.rs"
|
repository = "https://github.com/iqlusioninc/yubikey-piv.rs"
|
||||||
|
|||||||
+2
-3
@@ -2,10 +2,9 @@
|
|||||||
name = "yubikey-cli"
|
name = "yubikey-cli"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
description = """
|
description = """
|
||||||
Command-line interface for performing encryption and signing using RSA and/or
|
Command-line interface for performing encryption and signing using RSA/ECC keys stored on YubiKey devices.
|
||||||
ECC keys stored on YubiKey devices.
|
|
||||||
"""
|
"""
|
||||||
authors = ["Tony Arcieri <bascule@gmail.com>"]
|
authors = ["Tony Arcieri <tony@iqlusion.io>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "BSD-2-Clause"
|
license = "BSD-2-Clause"
|
||||||
repository = "https://github.com/iqlusioninc/yubikey-piv.rs"
|
repository = "https://github.com/iqlusioninc/yubikey-piv.rs"
|
||||||
|
|||||||
+38
-10
@@ -1,13 +1,16 @@
|
|||||||
//! Commands of the CLI application
|
//! Commands of the CLI application
|
||||||
|
|
||||||
pub mod list;
|
pub mod readers;
|
||||||
|
|
||||||
use self::list::ListCmd;
|
use self::readers::ReadersCmd;
|
||||||
use crate::status;
|
use crate::status::{self, STDOUT};
|
||||||
use gumdrop::Options;
|
use gumdrop::Options;
|
||||||
use std::env;
|
use std::{
|
||||||
use std::process::exit;
|
env,
|
||||||
use termcolor::ColorChoice;
|
io::{self, Write},
|
||||||
|
process::exit,
|
||||||
|
};
|
||||||
|
use termcolor::{ColorChoice, ColorSpec, WriteColor};
|
||||||
|
|
||||||
/// The `yubikey` CLI utility
|
/// The `yubikey` CLI utility
|
||||||
#[derive(Debug, Options)]
|
#[derive(Debug, Options)]
|
||||||
@@ -34,9 +37,34 @@ impl YubikeyCli {
|
|||||||
|
|
||||||
match &self.command {
|
match &self.command {
|
||||||
Some(cmd) => cmd.run(),
|
Some(cmd) => cmd.run(),
|
||||||
None => println!("{}", Commands::usage()),
|
None => Self::print_usage().unwrap(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Print usage information
|
||||||
|
pub fn print_usage() -> Result<(), io::Error> {
|
||||||
|
let mut stdout = STDOUT.lock();
|
||||||
|
stdout.reset()?;
|
||||||
|
|
||||||
|
let mut bold = ColorSpec::new();
|
||||||
|
bold.set_bold(true);
|
||||||
|
|
||||||
|
stdout.set_color(&bold)?;
|
||||||
|
writeln!(
|
||||||
|
stdout,
|
||||||
|
"{} {}",
|
||||||
|
env!("CARGO_PKG_NAME"),
|
||||||
|
env!("CARGO_PKG_VERSION")
|
||||||
|
)?;
|
||||||
|
stdout.reset()?;
|
||||||
|
|
||||||
|
writeln!(stdout, "{}", env!("CARGO_PKG_AUTHORS"))?;
|
||||||
|
writeln!(stdout, "{}", env!("CARGO_PKG_DESCRIPTION").trim())?;
|
||||||
|
writeln!(stdout)?;
|
||||||
|
writeln!(stdout, "{}", Commands::usage())?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Subcommands of this application
|
/// Subcommands of this application
|
||||||
@@ -50,9 +78,9 @@ pub enum Commands {
|
|||||||
#[options(help = "display version information")]
|
#[options(help = "display version information")]
|
||||||
Version(VersionOpts),
|
Version(VersionOpts),
|
||||||
|
|
||||||
/// `list` subcommand
|
/// `readers` subcommand
|
||||||
#[options(help = "list detected readers")]
|
#[options(help = "list detected readers")]
|
||||||
List(ListCmd),
|
Readers(ReadersCmd),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Commands {
|
impl Commands {
|
||||||
@@ -61,7 +89,7 @@ impl Commands {
|
|||||||
match self {
|
match self {
|
||||||
Commands::Help(help) => help.run(),
|
Commands::Help(help) => help.run(),
|
||||||
Commands::Version(version) => version.run(),
|
Commands::Version(version) => version.run(),
|
||||||
Commands::List(list) => list.run(),
|
Commands::Readers(list) => list.run(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ use gumdrop::Options;
|
|||||||
use std::process::exit;
|
use std::process::exit;
|
||||||
use yubikey_piv::readers::Readers;
|
use yubikey_piv::readers::Readers;
|
||||||
|
|
||||||
/// The `list` subcommand
|
/// The `readers` subcommand
|
||||||
#[derive(Debug, Options)]
|
#[derive(Debug, Options)]
|
||||||
pub struct ListCmd {}
|
pub struct ReadersCmd {}
|
||||||
|
|
||||||
impl ListCmd {
|
impl ReadersCmd {
|
||||||
/// Run the `list` subcommand
|
/// Run the `readers` subcommand
|
||||||
pub fn run(&self) {
|
pub fn run(&self) {
|
||||||
let mut readers = Readers::open().unwrap_or_else(|e| {
|
let mut readers = Readers::open().unwrap_or_else(|e| {
|
||||||
status_err!("couldn't open PC/SC context: {}", e);
|
status_err!("couldn't open PC/SC context: {}", e);
|
||||||
Reference in New Issue
Block a user