use clap::Parser;
mod app;
mod config;
mod merge_request;
mod utils;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Cli {
#[arg(long)]
dry_run: bool,
#[arg(long)]
assignee: Option<String>,
}
fn main() -> color_eyre::Result<()> {
color_eyre::install()?;
let cli = Cli::parse();
utils::ensure_glab_installed();
let mut cfg = config::load_config_from_toml();
if let Some(assignee) = cli.assignee {
cfg.assignee = Some(assignee);
}
cfg.dry_run = cli.dry_run;
let terminal = ratatui::init();
let app = app::App::new(cfg.clone());
let app = app.run(terminal)?;
ratatui::restore();
if !app.user_input_completed {
println!("Exiting without creating merge requests.");
return Ok(());
}
run_commands(cfg.dry_run, app);
Ok(())
}
fn run_commands(dry_run: bool, app: app::App) {
println!("Multi MR will now create merge requests for the following repositories:");
for dir_index in &app.selected_repos {
println!(" - {}", app.dirs[*dir_index]);
}
for dir_index in app.selected_repos {
let dir = app.dirs[dir_index].clone();
std::env::set_current_dir(app.config.working_dir.join(&dir))
.unwrap_or_else(|_| panic!("Failed to change directory to: {}", dir));
let cmd = app.mr.as_ref().expect("somehow no mr specified").create();
if dry_run {
app.mr
.as_ref()
.expect("somehow no mr specified")
.dry_run(cmd);
} else {
app.mr.as_ref().expect("somehow no mr specified").run(cmd);
}
}
}
#[cfg(test)]
mod test_main;