feat: updates
This commit is contained in:
28
src/main.rs
28
src/main.rs
@@ -1,11 +1,10 @@
|
||||
extern crate core;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
use rust_util::{failure, information, success, XResult};
|
||||
use rust_util::XResult;
|
||||
|
||||
use crate::cmd_decrypt::CmdDecrypt;
|
||||
use crate::cmd_encrypt::CmdEncrypt;
|
||||
use crate::cmd_info::CmdInfo;
|
||||
|
||||
mod util;
|
||||
@@ -17,6 +16,7 @@ mod file;
|
||||
mod card;
|
||||
mod cmd_info;
|
||||
mod cmd_decrypt;
|
||||
mod cmd_encrypt;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(name = "tiny-encrypt-rs")]
|
||||
@@ -30,10 +30,7 @@ struct Cli {
|
||||
enum Commands {
|
||||
/// Encrypt file(s)
|
||||
#[command(arg_required_else_help = true, short_flag = 'e')]
|
||||
Encrypt {
|
||||
/// Files need to be encrypted
|
||||
paths: Vec<PathBuf>,
|
||||
},
|
||||
Encrypt(CmdEncrypt),
|
||||
/// Decrypt file(s)
|
||||
#[command(arg_required_else_help = true, short_flag = 'd')]
|
||||
Decrypt(CmdDecrypt),
|
||||
@@ -45,21 +42,14 @@ enum Commands {
|
||||
fn main() -> XResult<()> {
|
||||
let args = Cli::parse();
|
||||
match args.command {
|
||||
Commands::Encrypt { paths } => {
|
||||
paths.iter().for_each(|f| information!("{:?}", f));
|
||||
Ok(())
|
||||
Commands::Encrypt(cmd_encrypt) => {
|
||||
cmd_encrypt::encrypt(cmd_encrypt)
|
||||
}
|
||||
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(())
|
||||
cmd_decrypt::decrypt(cmd_decrypt)
|
||||
}
|
||||
Commands::Info(command_info) => {
|
||||
cmd_info::info(&command_info)
|
||||
Commands::Info(cmd_info) => {
|
||||
cmd_info::info(cmd_info)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user