mod cli;
mod commands;
mod concurrency;
mod config;
mod hooks;
use anyhow::Result;
use clap::Parser;
use cli::{Cli, Commands, StackCommands};
fn main() {
if let Err(e) = run() {
eprintln!("error: {:#}", e);
std::process::exit(1);
}
}
fn setup_ssh_multiplexing() {
if std::env::var_os("GIT_SSH_COMMAND").is_some() {
return;
}
let dir = std::env::temp_dir();
let cmd = format!(
"ssh -o ControlMaster=auto -o ControlPath={}/giff-ssh-%C -o ControlPersist=120",
dir.display()
);
std::env::set_var("GIT_SSH_COMMAND", cmd);
}
fn run() -> Result<()> {
setup_ssh_multiplexing();
let cli = Cli::parse();
match cli.command {
Commands::Init => commands::init::run(),
Commands::New { branch } => commands::new::run(&branch),
Commands::Publish {
message,
branch,
all,
} => commands::publish::run(&message, branch.as_deref(), all),
Commands::Checkout { target } => commands::checkout::run(&target),
Commands::Next => commands::checkout::run_next(),
Commands::Prev => commands::checkout::run_prev(),
Commands::Commit {
message,
amend,
all,
} => commands::commit::run(message.as_deref(), amend, all),
Commands::Push => commands::push::run(),
Commands::Sync { r#continue } => commands::sync::run(r#continue),
Commands::Log { all } => commands::log::run(all),
Commands::Status => commands::status::run(),
Commands::Dashboard => commands::dashboard::run(),
Commands::Stack { command } => match command {
StackCommands::Reorder => commands::stack::reorder::run(),
StackCommands::Squash { frame } => commands::stack::squash::run(&frame),
StackCommands::Drop { frame } => commands::stack::drop::run(&frame),
StackCommands::Land { method } => commands::stack::land::run(&method),
},
Commands::ParentBranch => commands::parent_branch::run(),
}
}