kaishin 0.4.0

Universal self-update library for Rust CLIs, extracted from rvpm and renri.
Documentation

kaishin

Universal self-update library for Rust CLIs, extracted from rvpm and renri.

Features

  • GitHub Releases API integration
  • Automatic installation method detection (cargo install / dev build / direct binary)
  • Background update check with throttling via [Checker]
  • Customizable update banner
  • Interactive/Non-interactive update flow

Usage

Add this to your Cargo.toml:

[dependencies]

kaishin = "0.1"

Self-Update Command

use kaishin::{KaishinOptions, UpdateOptions, run_self_update};

#[tokio::main]
async fn main() -> Result<()> {
    let opts = KaishinOptions::new(
        "yukimemi",
        "my-tool",
        "my-tool",
        env!("CARGO_PKG_VERSION")
    );
    let upd_opts = UpdateOptions::new()
        .yes(args.yes)
        .check_only(args.check)
        .non_interactive(args.non_interactive);

    // Run self-update command
    run_self_update(&opts, upd_opts).await?;
    // Note: In non-interactive mode (non_interactive: true), the updater will exit 
    // unless --yes (yes: true) is provided.

    Ok(())
}

Background Update Check

Using Checker to handle state and throttling automatically:

use kaishin::{KaishinOptions, Checker};

#[tokio::main]
async fn main() -> Result<()> {
    let opts = KaishinOptions::new("yukimemi", "rvpm", "rvpm", env!("CARGO_PKG_VERSION"));
    let checker = Checker::new("rvpm", opts);

    // 1. Check in background (with 24h throttle)
    if checker.should_check() {
        let checker_clone = checker.clone();
        tokio::spawn(async move {
            let _ = checker_clone.check_and_save().await;
        });
    }

    // ... run app ...

    // 2. Show banner at the end if update is available
    if let Some(latest) = checker.cached_update() {
        eprintln!("\n{}", checker.format_banner(&latest));
    }

    Ok(())
}

License

MIT