#[macro_use] extern crate rust_util; use clap::{App, AppSettings, ArgMatches}; use rust_util::util_clap::{Command, CommandError}; mod sshutil; mod fido; mod digest; mod rsautil; mod pkiutil; mod pgpcardutil; mod cmd_list; mod cmd_u2fregister; mod cmd_u2fsign; mod cmd_rsaencrypt; mod cmd_rsadecrypt; mod cmd_rsaverify; mod cmd_pgp; mod cmd_pgpcardadmin; mod cmd_pgpcardlist; mod cmd_pgpcardsign; mod cmd_pgpcarddecrypt; mod cmd_pgpcardmake; mod cmd_piv; mod cmd_pivmeta; mod cmd_pivsign; mod cmd_pivecdh; mod cmd_pivdecrypt; mod cmd_pivgenerate; mod cmd_chall; mod cmd_challconfig; mod cmd_sshagent; 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() { match inner_main() { Err(e) => failure_and_exit!("Run cli error: {}", e), Ok(Some(code)) => std::process::exit(code), Ok(None) => (), } } fn inner_main() -> CommandError { let commands: Vec> = vec![ Box::new(cmd_list::CommandImpl), Box::new(cmd_chall::CommandImpl), Box::new(cmd_challconfig::CommandImpl), Box::new(cmd_rsaencrypt::CommandImpl), Box::new(cmd_rsadecrypt::CommandImpl), Box::new(cmd_rsaverify::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_pgpcardmake::CommandImpl), Box::new(cmd_piv::CommandImpl), Box::new(cmd_pivmeta::CommandImpl), Box::new(cmd_pivsign::CommandImpl), Box::new(cmd_pivecdh::CommandImpl), Box::new(cmd_pivdecrypt::CommandImpl), Box::new(cmd_pivgenerate::CommandImpl), Box::new(cmd_u2fregister::CommandImpl), Box::new(cmd_u2fsign::CommandImpl), Box::new(cmd_sshagent::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) }