Implement embedded Git synchronization TUI
This commit is contained in:
@@ -11,8 +11,20 @@ const ROOT_COMMANDS: &[&str] = &[
|
||||
"git", "otp", "lock", "unlock", "help", "version", "quit",
|
||||
];
|
||||
const GIT_COMMANDS: &[&str] = &[
|
||||
"init", "status", "log", "diff", "add", "commit", "remote", "config", "fetch", "pull", "push",
|
||||
"init",
|
||||
"status",
|
||||
"log",
|
||||
"diff",
|
||||
"add",
|
||||
"commit",
|
||||
"remote",
|
||||
"config",
|
||||
"fetch",
|
||||
"pull",
|
||||
"push",
|
||||
"sync",
|
||||
"resolve-local",
|
||||
"resolve-remote",
|
||||
];
|
||||
const GIT_REMOTE_COMMANDS: &[&str] = &["get-url", "add", "set-url", "remove"];
|
||||
const OTP_COMMANDS: &[&str] = &["code", "insert", "append", "uri", "validate", "version"];
|
||||
@@ -55,6 +67,8 @@ pub const COMMAND_COVERAGE: &[CommandCoverage] = &[
|
||||
coverage("pull Git remote", ":git pull [REMOTE] [BRANCH]"),
|
||||
coverage("push Git remote", ":git push [REMOTE] [BRANCH]"),
|
||||
coverage("synchronize Git remote", ":git sync [REMOTE]"),
|
||||
coverage("resolve Git conflicts locally", ":git resolve-local"),
|
||||
coverage("resolve Git conflicts remotely", ":git resolve-remote"),
|
||||
coverage("generate an OTP code", ":otp code [OPTIONS] ENTRY"),
|
||||
coverage("insert an OTP entry", ":otp insert [OPTIONS] [ENTRY]"),
|
||||
coverage("append OTP data", ":otp append [OPTIONS] ENTRY"),
|
||||
@@ -84,6 +98,7 @@ pub enum CommandInvocation {
|
||||
Lock,
|
||||
Unlock,
|
||||
Quit,
|
||||
ResolveGit(ironstorage::git::GitConflictChoice),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
@@ -334,10 +349,26 @@ pub fn parse_command(input: &str) -> Result<CommandInvocation, CommandError> {
|
||||
let Some(command) = tokens.first().map(String::as_str) else {
|
||||
return Err(CommandError::new("command is empty"));
|
||||
};
|
||||
if tokens.as_slice() == ["git", "resolve-local"] {
|
||||
return Ok(CommandInvocation::ResolveGit(
|
||||
ironstorage::git::GitConflictChoice::Local,
|
||||
));
|
||||
}
|
||||
if tokens.as_slice() == ["git", "resolve-remote"] {
|
||||
return Ok(CommandInvocation::ResolveGit(
|
||||
ironstorage::git::GitConflictChoice::Remote,
|
||||
));
|
||||
}
|
||||
let builtin = match command {
|
||||
"lock" => Some(CommandInvocation::Lock),
|
||||
"unlock" => Some(CommandInvocation::Unlock),
|
||||
"quit" | "q" => Some(CommandInvocation::Quit),
|
||||
"git-resolve-local" => Some(CommandInvocation::ResolveGit(
|
||||
ironstorage::git::GitConflictChoice::Local,
|
||||
)),
|
||||
"git-resolve-remote" => Some(CommandInvocation::ResolveGit(
|
||||
ironstorage::git::GitConflictChoice::Remote,
|
||||
)),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(invocation) = builtin {
|
||||
@@ -758,6 +789,18 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn destructive_and_nested_requests_preserve_typed_storage_contracts() {
|
||||
assert_eq!(
|
||||
parse_command("git resolve-local"),
|
||||
Ok(CommandInvocation::ResolveGit(
|
||||
ironstorage::git::GitConflictChoice::Local
|
||||
))
|
||||
);
|
||||
assert_eq!(
|
||||
parse_command("git resolve-remote"),
|
||||
Ok(CommandInvocation::ResolveGit(
|
||||
ironstorage::git::GitConflictChoice::Remote
|
||||
))
|
||||
);
|
||||
assert_eq!(
|
||||
parse_command("remove -r folder"),
|
||||
Ok(CommandInvocation::Storage(CommandRequest::Remove(
|
||||
|
||||
Reference in New Issue
Block a user