diff --git a/src/parsing.rs b/src/parsing.rs index bd2f508..c1fba47 100644 --- a/src/parsing.rs +++ b/src/parsing.rs @@ -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, - #[arg(short = 'i')] - key: Option, - #[arg(short = 'f')] - force: bool, - }, + Open(OpenOperation), /// Compress and encrypt a directory into a drawer file - Close { - drawer_file: PathBuf, - target_path: Option, - #[arg(short = 'i')] - key: Option, - }, + 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, - }, + Info(InfoOperation), +} + +#[derive(Parser, Debug)] +struct OpenOperation { + drawer_file: PathBuf, + target_path: Option, + #[arg(short = 'i')] + key: Option, + #[arg(short = 'f')] + force: bool, +} + +#[derive(Parser, Debug)] +struct CloseOperation { + drawer_file: PathBuf, + target_path: Option, + #[arg(short = 'i')] + key: Option, +} + +#[derive(Parser, Debug)] +struct KeyOperation { + filename: PathBuf, +} + +#[derive(Parser, Debug)] +struct InfoOperation { + drawer_file: PathBuf, + #[arg(short = 'i')] + key: Option, } pub fn parse_args(args: I) -> Result @@ -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,