Add additive KDBX importer
This commit is contained in:
1 parent
f84f7247d2
commit
bf75465642
23 files changed
+1959
-82
No files matched your search
@@ -6,6 +6,7 @@ use clap::{Args, CommandFactory, Parser, Subcommand, error::ErrorKind};
|
||||
use clap_complete::{Shell, generate};
|
||||
|
||||
use crate::PRODUCT_NAME;
|
||||
use crate::kdbx::{KdbxImportMode, KdbxImportRequest};
|
||||
|
||||
pub const EXIT_SUCCESS: u8 = 0;
|
||||
pub const EXIT_FAILURE: u8 = 1;
|
||||
@@ -52,6 +53,7 @@ pub enum CommandRequest {
|
||||
Remove(RemoveRequest),
|
||||
Move(MoveRequest),
|
||||
Copy(CopyRequest),
|
||||
ImportKdbx(KdbxImportRequest),
|
||||
Git(GitRequest),
|
||||
Otp(OtpRequest),
|
||||
Completion { shell: CompletionShell },
|
||||
@@ -329,6 +331,7 @@ pub enum HelpTopic {
|
||||
Remove,
|
||||
Move,
|
||||
Copy,
|
||||
ImportKdbx,
|
||||
Git,
|
||||
Otp,
|
||||
}
|
||||
@@ -347,6 +350,7 @@ impl HelpTopic {
|
||||
"rm" | "remove" | "delete" => Some(Self::Remove),
|
||||
"mv" | "rename" => Some(Self::Move),
|
||||
"cp" | "copy" => Some(Self::Copy),
|
||||
"import-kdbx" => Some(Self::ImportKdbx),
|
||||
"git" => Some(Self::Git),
|
||||
"otp" => Some(Self::Otp),
|
||||
_ => None,
|
||||
@@ -366,6 +370,7 @@ impl HelpTopic {
|
||||
Self::Remove => "rm",
|
||||
Self::Move => "mv",
|
||||
Self::Copy => "cp",
|
||||
Self::ImportKdbx => "import-kdbx",
|
||||
Self::Git => "git",
|
||||
Self::Otp => "otp",
|
||||
}
|
||||
@@ -480,6 +485,8 @@ enum CommandArguments {
|
||||
Move(MoveArguments),
|
||||
#[command(name = "cp", visible_alias = "copy")]
|
||||
Copy(CopyArguments),
|
||||
#[command(name = "import-kdbx")]
|
||||
ImportKdbx(ImportKdbxArguments),
|
||||
Git(GitArguments),
|
||||
Otp(OtpArguments),
|
||||
Completion(CompletionArguments),
|
||||
@@ -616,6 +623,15 @@ struct CopyArguments {
|
||||
destination: String,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
struct ImportKdbxArguments {
|
||||
source: PathBuf,
|
||||
#[arg(long, value_name = "PATH")]
|
||||
key_file: Option<PathBuf>,
|
||||
#[arg(long)]
|
||||
quick_add: bool,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
struct GitArguments {
|
||||
#[command(subcommand)]
|
||||
@@ -824,6 +840,17 @@ fn convert_arguments(arguments: CliArguments) -> Result<CliInvocation, CliParseE
|
||||
destination: arguments.destination,
|
||||
force: arguments.force,
|
||||
}),
|
||||
Some(CommandArguments::ImportKdbx(arguments)) => {
|
||||
CommandRequest::ImportKdbx(KdbxImportRequest::new(
|
||||
arguments.source,
|
||||
arguments.key_file,
|
||||
if arguments.quick_add {
|
||||
KdbxImportMode::QuickAdd
|
||||
} else {
|
||||
KdbxImportMode::AddAndUpdate
|
||||
},
|
||||
))
|
||||
}
|
||||
Some(CommandArguments::Git(arguments)) => {
|
||||
CommandRequest::Git(convert_git(arguments.command)?)
|
||||
}
|
||||
@@ -987,6 +1014,7 @@ fn normalize_dispatch(mut arguments: Vec<OsString>) -> Vec<OsString> {
|
||||
"rename",
|
||||
"cp",
|
||||
"copy",
|
||||
"import-kdbx",
|
||||
"git",
|
||||
"otp",
|
||||
"help",
|
||||
|
||||
Reference in new issue
Block a user