gitquick 0.3.0

Command line tool that simplifies common git workflows.
use clap::{Args, CommandFactory, Parser, Subcommand};

mod add;
mod branch;
mod checkout;
mod commit;
mod config;
mod git_operations;
mod rebase;
mod revert;

#[derive(Parser)]
#[command(name = "gq", version = env!("CARGO_PKG_VERSION"), about = "GitQuick: Simplify your git workflow")]
struct Cli {
    #[command(subcommand)]
    command: Option<Commands>,
}

#[derive(Args)]
struct ConfigArgs {
    key: String,
    value: String,
}

#[derive(Subcommand)]
enum Commands {
    #[command(about = "Get and set options")]
    Config(ConfigArgs),
    #[command(about = "Add contents of new or changed files to the index")]
    Add,
    #[command(about = "Record changes to the repository")]
    Commit {
        #[arg(long = "fixup", help = "Create a new branch")]
        fixup: bool,
        #[arg(long = "amend", help = "Modify most recent commit")]
        amend: bool,
    },
    #[command(about = "List, create, or delete branches")]
    Branch {
        #[arg(short = 'd', long = "delete", help = "Delete a branch")]
        delete: bool,
        #[arg(short = 'D', help = "Force delete a branch")]
        force_delete: bool,
    },
    #[command(about = "Switch branches or restore working tree files")]
    Checkout {
        #[arg(short = 'b', long = "branch", help = "Create a new branch")]
        create_new: bool,
    },
    #[command(about = "Revert some existing commits")]
    Revert,
    #[command(about = "Reapply commits on top of another base tip")]
    Rebase {
        #[arg(
            short = 'i',
            long = "interactive",
            help = "Let user edit list before rebasing"
        )]
        interactive: bool,
    },
}

fn main() {
    let cli = Cli::parse();
    let config = config::load_config();
    let result = match &cli.command {
        Some(Commands::Commit { fixup, amend }) => {
            commit::run_commit(config.commit, *fixup, *amend)
        }
        Some(Commands::Branch {
            delete,
            force_delete,
        }) => branch::run_branch(*delete, *force_delete),
        Some(Commands::Checkout { create_new }) => checkout::run_checkout(*create_new),
        Some(Commands::Revert) => revert::run_revert(),
        Some(Commands::Config(args)) => config::run_config(args),
        Some(Commands::Add) => add::stage_files(),
        Some(Commands::Rebase { interactive }) => rebase::run_rebase(*interactive),
        None => {
            Cli::command().print_help().unwrap();
            Ok(())
        }
    };

    if let Err(err) = result {
        eprintln!("❌ Error: {}", err);
        std::process::exit(1);
    }
}