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