Merge pull request #71 from iqlusioninc/cli/rename-list-to-readers-improve-usage
cli: rename 'list' command to 'readers'; improve 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)
|
||||
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"
|
||||
license = "BSD-2-Clause"
|
||||
repository = "https://github.com/iqlusioninc/yubikey-piv.rs"
|
||||
|
||||
+2
-3
@@ -2,10 +2,9 @@
|
||||
name = "yubikey-cli"
|
||||
version = "0.0.1"
|
||||
description = """
|
||||
Command-line interface for performing encryption and signing using RSA and/or
|
||||
ECC keys stored on YubiKey devices.
|
||||
Command-line interface for performing encryption and signing using RSA/ECC keys stored on YubiKey devices.
|
||||
"""
|
||||
authors = ["Tony Arcieri <bascule@gmail.com>"]
|
||||
authors = ["Tony Arcieri <tony@iqlusion.io>"]
|
||||
edition = "2018"
|
||||
license = "BSD-2-Clause"
|
||||
repository = "https://github.com/iqlusioninc/yubikey-piv.rs"
|
||||
|
||||
+38
-10
@@ -1,13 +1,16 @@
|
||||
//! Commands of the CLI application
|
||||
|
||||
pub mod list;
|
||||
pub mod readers;
|
||||
|
||||
use self::list::ListCmd;
|
||||
use crate::status;
|
||||
use self::readers::ReadersCmd;
|
||||
use crate::status::{self, STDOUT};
|
||||
use gumdrop::Options;
|
||||
use std::env;
|
||||
use std::process::exit;
|
||||
use termcolor::ColorChoice;
|
||||
use std::{
|
||||
env,
|
||||
io::{self, Write},
|
||||
process::exit,
|
||||
};
|
||||
use termcolor::{ColorChoice, ColorSpec, WriteColor};
|
||||
|
||||
/// The `yubikey` CLI utility
|
||||
#[derive(Debug, Options)]
|
||||
@@ -34,9 +37,34 @@ impl YubikeyCli {
|
||||
|
||||
match &self.command {
|
||||
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
|
||||
@@ -50,9 +78,9 @@ pub enum Commands {
|
||||
#[options(help = "display version information")]
|
||||
Version(VersionOpts),
|
||||
|
||||
/// `list` subcommand
|
||||
/// `readers` subcommand
|
||||
#[options(help = "list detected readers")]
|
||||
List(ListCmd),
|
||||
Readers(ReadersCmd),
|
||||
}
|
||||
|
||||
impl Commands {
|
||||
@@ -61,7 +89,7 @@ impl Commands {
|
||||
match self {
|
||||
Commands::Help(help) => help.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 yubikey_piv::readers::Readers;
|
||||
|
||||
/// The `list` subcommand
|
||||
/// The `readers` subcommand
|
||||
#[derive(Debug, Options)]
|
||||
pub struct ListCmd {}
|
||||
pub struct ReadersCmd {}
|
||||
|
||||
impl ListCmd {
|
||||
/// Run the `list` subcommand
|
||||
impl ReadersCmd {
|
||||
/// Run the `readers` subcommand
|
||||
pub fn run(&self) {
|
||||
let mut readers = Readers::open().unwrap_or_else(|e| {
|
||||
status_err!("couldn't open PC/SC context: {}", e);
|
||||
Reference in New Issue
Block a user