mirror of
https://git.um-react.app/um/lib_um_crypto_rust.git
synced 2026-03-08 04:29:54 +00:00
feat: add experimental cli
This commit is contained in:
44
um_cli/src/main.rs
Normal file
44
um_cli/src/main.rs
Normal file
@@ -0,0 +1,44 @@
|
||||
use crate::cmd::Commands;
|
||||
use anyhow::Result;
|
||||
use clap::Parser;
|
||||
use std::process::exit;
|
||||
use std::time::Instant;
|
||||
|
||||
mod cmd;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(name = "um_cli")]
|
||||
#[command(version = "0.1")]
|
||||
#[command(about = "um_cli (rust ver.)", long_about = None)]
|
||||
struct Cli {
|
||||
#[clap(subcommand)]
|
||||
command: Option<Commands>,
|
||||
|
||||
/// Time command
|
||||
#[clap(long, short, action=clap::ArgAction::SetTrue)]
|
||||
time: Option<bool>,
|
||||
}
|
||||
|
||||
fn run_command(cli: &Cli) -> Result<i32> {
|
||||
match &cli.command {
|
||||
Some(Commands::QMCv1(cmd)) => cmd.run(),
|
||||
None => {
|
||||
// https://github.com/clap-rs/clap/issues/3857#issuecomment-1161796261
|
||||
todo!("implement a sensible default command, similar to um/cli");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let cli = Cli::parse();
|
||||
let start = Instant::now();
|
||||
let code = run_command(&cli).unwrap_or_else(|err| {
|
||||
eprintln!("failed to run command: {}", err);
|
||||
-1
|
||||
});
|
||||
let duration = start.elapsed();
|
||||
if let Some(true) = cli.time {
|
||||
eprintln!("time: {:?}", duration);
|
||||
};
|
||||
exit(code);
|
||||
}
|
||||
Reference in New Issue
Block a user