This commit is contained in:
2026-05-13 19:54:20 -05:00
parent becab7abd6
commit 7f7fcf6fa6
+38 -26
View File
@@ -42,31 +42,43 @@ struct Cli {
#[derive(Subcommand)]
enum Command {
/// Decrypt and expand a drawer file into a directory
Open {
drawer_file: PathBuf,
target_path: Option<PathBuf>,
#[arg(short = 'i')]
key: Option<PathBuf>,
#[arg(short = 'f')]
force: bool,
},
Open(OpenOperation),
/// Compress and encrypt a directory into a drawer file
Close {
drawer_file: PathBuf,
target_path: Option<PathBuf>,
#[arg(short = 'i')]
key: Option<PathBuf>,
},
Close(CloseOperation),
/// Generate a new SSH key and save it to a file
Key {
filename: PathBuf,
},
Key(KeyOperation),
/// Show information about a drawer file
Info {
drawer_file: PathBuf,
#[arg(short = 'i')]
key: Option<PathBuf>,
},
Info(InfoOperation),
}
#[derive(Parser, Debug)]
struct OpenOperation {
drawer_file: PathBuf,
target_path: Option<PathBuf>,
#[arg(short = 'i')]
key: Option<PathBuf>,
#[arg(short = 'f')]
force: bool,
}
#[derive(Parser, Debug)]
struct CloseOperation {
drawer_file: PathBuf,
target_path: Option<PathBuf>,
#[arg(short = 'i')]
key: Option<PathBuf>,
}
#[derive(Parser, Debug)]
struct KeyOperation {
filename: PathBuf,
}
#[derive(Parser, Debug)]
struct InfoOperation {
drawer_file: PathBuf,
#[arg(short = 'i')]
key: Option<PathBuf>,
}
pub fn parse_args<I, T>(args: I) -> Result<DrawerOperation, DrawerError>
@@ -78,7 +90,7 @@ where
.map_err(|e| DrawerError::ParseError(e.to_string()))?;
match cli.command {
Command::Open { drawer_file, target_path, key, force } => {
Command::Open(OpenOperation { drawer_file, target_path, key, force }) => {
let key = resolve_key(key);
Ok(DrawerOperation {
operation_type: OperationType::Open,
@@ -88,7 +100,7 @@ where
force,
})
}
Command::Close { drawer_file, target_path, key } => {
Command::Close(CloseOperation { drawer_file, target_path, key }) => {
let key = resolve_key(key);
Ok(DrawerOperation {
operation_type: OperationType::Close,
@@ -98,7 +110,7 @@ where
force: false,
})
}
Command::Key { filename } => {
Command::Key(KeyOperation { filename }) => {
Ok(DrawerOperation {
operation_type: OperationType::Key,
drawer_file: filename,
@@ -107,7 +119,7 @@ where
force: false,
})
}
Command::Info { drawer_file, key } => {
Command::Info(InfoOperation { drawer_file, key }) => {
let key = resolve_key(key);
Ok(DrawerOperation {
operation_type: OperationType::Info,