branchdiff 0.60.1

Terminal UI showing unified diff of current branch vs its base
Documentation
//! Generates man pages and shell completions for distribution.
//!
//! Run with: cargo run --example generate_assets
//! Output goes to target/assets/ by default, or set BRANCHDIFF_ASSETS_DIR.

use std::path::PathBuf;

use clap::CommandFactory;
use clap_complete::Shell;

fn main() {
    let out_dir = PathBuf::from(
        std::env::var("BRANCHDIFF_ASSETS_DIR").unwrap_or_else(|_| "target/assets".into()),
    );
    let completions_dir = out_dir.join("completions");
    std::fs::create_dir_all(&completions_dir).expect("failed to create output directories");

    let mut cmd = branchdiff::cli::Cli::command();

    // Man page
    let man = clap_mangen::Man::new(cmd.clone());
    let mut buf = Vec::new();
    man.render(&mut buf).expect("failed to render man page");
    std::fs::write(out_dir.join("branchdiff.1"), buf).expect("failed to write man page");

    // Shell completions
    for shell in [Shell::Bash, Shell::Zsh, Shell::Fish] {
        clap_complete::generate_to(shell, &mut cmd, "branchdiff", &completions_dir)
            .expect("failed to generate completions");
    }

    println!("Generated assets in {}", out_dir.display());
}