#[macro_use] extern crate rust_util; use clap::{App, AppSettings, ArgMatches}; use rust_util::util_clap::{Command, CommandError}; mod fido; mod digest; #[allow(unused)] // pending use in pgpcardimport mod rsautil; mod pkiutil; mod pgpcardutil; mod cmd_u2fregister; mod cmd_u2fsign; mod cmd_pgp; mod cmd_pgpcardadmin; mod cmd_pgpcardlist; mod cmd_pgpcardsign; mod cmd_pgpcarddecrypt; mod cmd_piv; mod cmd_pivsign; mod cmd_chall; mod cmd_challconfig; pub struct DefaultCommandImpl; impl DefaultCommandImpl { pub fn process_command<'a>(app: App<'a, 'a>) -> App<'a, 'a> { app } pub fn run(_arg_matches: &ArgMatches) -> CommandError { information!("Card(WebAuthn, OpenPGP, YubiKey) cli, use --help for help"); Ok(None) } } fn main() { if let Err(e) = inner_main() { failure_and_exit!("Run cli error: {}", e); } } fn inner_main() -> CommandError { let commands: Vec> = vec![ Box::new(cmd_chall::CommandImpl), Box::new(cmd_challconfig::CommandImpl), Box::new(cmd_pgp::CommandImpl), Box::new(cmd_pgpcardadmin::CommandImpl), Box::new(cmd_pgpcardlist::CommandImpl), Box::new(cmd_pgpcardsign::CommandImpl), Box::new(cmd_pgpcarddecrypt::CommandImpl), Box::new(cmd_piv::CommandImpl), Box::new(cmd_pivsign::CommandImpl), Box::new(cmd_u2fregister::CommandImpl), Box::new(cmd_u2fsign::CommandImpl), ]; let mut app = App::new(env!("CARGO_PKG_NAME")) .version(env!("CARGO_PKG_VERSION")) .about(env!("CARGO_PKG_DESCRIPTION")) .long_about("Card Cli is a command tool for WebAuthn, OpenPGP, YubiKey ... smart cards") .setting(AppSettings::ColoredHelp); app = DefaultCommandImpl::process_command(app); for command in &commands { app = app.subcommand(command.subcommand()); } let matches = app.get_matches(); for command in &commands { if let Some(sub_cmd_matches) = matches.subcommand_matches(command.name()) { return command.run(&matches, sub_cmd_matches); } } DefaultCommandImpl::run(&matches) }