furet 0.3.0

Postgres and ClickHouse per repo: tunnels, read-only remotes, rows you can follow, for you and your agents
//! Whether a newer furet is out (asked of GitHub at most twice a day), and `furet update`.

use anyhow::Result;
use herdr_kit::update::{Cargo, Releases};
use std::process::Command;

pub const INSTALL: &str =
    "curl -LsSf https://github.com/gaspb/furet/releases/latest/download/furet-installer.sh | sh";

fn releases() -> Releases {
    Releases::new("furet", "gaspb/furet", env!("CARGO_PKG_VERSION"))
}

/// A newer release than this binary, if the last check found one.
pub fn available() -> Option<String> {
    releases().available()
}

/// Keeps `available` current; `FURET_NO_UPDATE_CHECK=1` turns it off.
pub fn watch() {
    releases().watch();
}

/// `furet update`: the installer's updater (or cargo), then the panel and the engine follow.
pub fn run() -> Result<i32> {
    let status = releases().update(Cargo::Registry("furet"), INSTALL)?;
    if !status.success() {
        return Ok(status.code().unwrap_or(1));
    }
    // The new binary refreshes the panel and replaces the engine; open panels reconnect.
    let exe = std::env::current_exe()?;
    let _ = Command::new(&exe).args(["serve", "--stop"]).status();
    Command::new(&exe).args(["setup", "herdr"]).status()?;
    Ok(0)
}