use crate::prelude::*;
pub mod cli;
pub mod commands;
pub mod config;
pub mod error;
pub mod git;
pub mod output;
use cli::Commands;
use std::env;
pub fn execute(command: Commands, verbose: bool, dry_run: bool) -> anyhow::Result<()> {
let repo_root = env::current_dir().unwrap_or_else(|_| PathBuf::from("."));
let result = match command {
Commands::Status => commands::status::execute(&repo_root, verbose),
Commands::Discard { untracked, yes } => commands::discard::execute(
&repo_root,
commands::discard::Options {
untracked,
assume_yes: yes,
dry_run,
},
),
Commands::Checkout {
branch,
create,
ignore_missing,
} => commands::checkout::execute(
&repo_root,
&branch,
create,
ignore_missing,
dry_run,
verbose,
),
Commands::Pull {
rebase,
autostash,
overwrite_local,
} => {
let options = crate::git_backend::PullOptions {
rebase,
autostash,
overwrite_local,
};
commands::pull::execute(&repo_root, options, dry_run, verbose)
}
Commands::Push {
force_with_lease,
force_all,
} => commands::push::execute(&repo_root, force_with_lease, force_all, dry_run, verbose),
Commands::Create {
branch,
from,
push,
force_all,
} => commands::create::execute(
&repo_root,
&branch,
from.as_deref(),
push,
force_all,
dry_run,
verbose,
),
Commands::Commit {
message,
push,
stage_all,
exclude,
include,
force_all,
} => commands::commit::execute(
&repo_root, &message, push, stage_all, &exclude, &include, force_all, dry_run, verbose,
),
Commands::Sync { init, recursive } => {
commands::sync::execute(&repo_root, init, recursive, dry_run, verbose)
}
Commands::Delete {
branch,
remote,
force,
} => commands::delete::execute(&repo_root, &branch, remote, force, dry_run, verbose),
Commands::Fetch { all, force_all } => {
commands::fetch::execute(&repo_root, all, force_all, dry_run, verbose)
}
Commands::Branch { all } => commands::branch::execute(&repo_root, all, verbose),
Commands::Init { recursive } => {
commands::init::execute(&repo_root, recursive, dry_run, verbose)
}
Commands::Diff {
base,
since,
output,
staged,
clean,
} => commands::diff::execute(
&repo_root,
base.as_deref(),
since.as_deref(),
&output,
staged,
clean,
verbose,
),
Commands::Stage => commands::stage::execute(&repo_root, dry_run, verbose),
Commands::MergeBack { message } => {
commands::merge_back::execute(&repo_root, &message, dry_run, verbose)
}
Commands::TestCatalog {
output,
git_add,
quiet,
} => commands::catalogue::execute(&repo_root, output.as_deref(), git_add, quiet)
.map_err(|e| crate::fleet::error::SuperGitError::Other(format!("{}", e))),
};
result.map_err(|e| anyhow::anyhow!("{}", e))
}