a73x

src/main.rs

Ref:   Size: 1.0 KiB

use clap::{CommandFactory, Parser};
use git2::Repository;

use git_collab::cli::{Cli, Commands};

fn main() {
    let cli = Cli::parse();

    // Handle completions before opening the repo (no git repo needed)
    if let Commands::Completions { shell } = &cli.command {
        clap_complete::generate(
            *shell,
            &mut Cli::command(),
            "git-collab",
            &mut std::io::stdout(),
        );
        return;
    }

    let repo = match Repository::open_from_env() {
        Ok(r) => r,
        Err(e) => {
            eprintln!("error: {}", e);
            std::process::exit(1);
        }
    };

    if let Err(e) = git_collab::run(cli, &repo) {
        match &e {
            git_collab::error::Error::PartialSync { .. } => {
                // Summary already printed by sync; just exit with code 1
                std::process::exit(1);
            }
            _ => {
                eprintln!("error: {}", e);
                std::process::exit(1);
            }
        }
    }
}