feat: update subcmd
This commit is contained in:
32
src/main.rs
32
src/main.rs
@@ -5,6 +5,9 @@ use std::path::PathBuf;
|
||||
use clap::{Parser, Subcommand};
|
||||
use rust_util::{failure, information, success, XResult};
|
||||
|
||||
use crate::cmd_decrypt::CmdDecrypt;
|
||||
use crate::cmd_info::CmdInfo;
|
||||
|
||||
mod util;
|
||||
mod config;
|
||||
mod spec;
|
||||
@@ -33,25 +36,10 @@ enum Commands {
|
||||
},
|
||||
/// Decrypt file(s)
|
||||
#[command(arg_required_else_help = true, short_flag = 'd')]
|
||||
Decrypt {
|
||||
/// Files need to be decrypted
|
||||
paths: Vec<PathBuf>,
|
||||
/// PIN
|
||||
#[arg(long)]
|
||||
pin: Option<String>,
|
||||
/// SLOT
|
||||
#[arg(long)]
|
||||
slot: Option<String>,
|
||||
},
|
||||
Decrypt(CmdDecrypt),
|
||||
/// Show file info
|
||||
#[command(arg_required_else_help = true, short_flag = 'I')]
|
||||
Info {
|
||||
/// File
|
||||
path: PathBuf,
|
||||
/// Show raw meta
|
||||
#[arg(long, default_value_t = false)]
|
||||
raw_meta: bool,
|
||||
},
|
||||
Info(CmdInfo),
|
||||
}
|
||||
|
||||
fn main() -> XResult<()> {
|
||||
@@ -61,17 +49,17 @@ fn main() -> XResult<()> {
|
||||
paths.iter().for_each(|f| information!("{:?}", f));
|
||||
Ok(())
|
||||
}
|
||||
Commands::Decrypt { paths, pin, slot } => {
|
||||
for path in &paths {
|
||||
match cmd_decrypt::decrypt(path, &pin, &slot) {
|
||||
Commands::Decrypt(cmd_decrypt) => {
|
||||
for path in &cmd_decrypt.paths {
|
||||
match cmd_decrypt::decrypt(path, &cmd_decrypt.pin, &cmd_decrypt.slot) {
|
||||
Ok(_) => success!("Decrypt {} succeed", path.to_str().unwrap_or("N/A")),
|
||||
Err(e) => failure!("Decrypt {} failed: {}", path.to_str().unwrap_or("N/A"), e),
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Commands::Info { path, raw_meta } => {
|
||||
cmd_info::info(path, raw_meta)
|
||||
Commands::Info(command_info) => {
|
||||
cmd_info::info(&command_info)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user