wsb 0.164.718

Workspace - A tool suite for file operations, version management, and development workflow automation
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;

/// Execute git commands across a fleet rooted at the current directory.
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::Checkout { branch, create } => {
            commands::checkout::execute(&repo_root, &branch, create, dry_run, verbose)
        }

        Commands::Pull { rebase } => commands::pull::execute(&repo_root, rebase, dry_run, verbose),

        Commands::Push { force_with_lease } => {
            commands::push::execute(&repo_root, force_with_lease, dry_run, verbose)
        }

        Commands::Create { branch, from, push } => {
            commands::create::execute(&repo_root, &branch, from.as_deref(), push, dry_run, verbose)
        }

        Commands::Commit { message, push } => {
            commands::commit::execute(&repo_root, &message, push, 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 } => commands::fetch::execute(&repo_root, 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,
            output,
            staged,
        } => commands::diff::execute(&repo_root, base.as_deref(), &output, staged, verbose),

        Commands::Stage => commands::stage::execute(&repo_root, dry_run, verbose),

        Commands::MergeBack { message } => {
            commands::merge_back::execute(&repo_root, &message, dry_run, verbose)
        }
    };

    result.map_err(|e| anyhow::anyhow!("{}", e))
}