runtime-cli 0.1.0

Command-line client for managing git projects on Runtime
Documentation
//! `runtime backup` — operator-facing snapshot operations.
//!
//! `runtime backup create` — calls the admin-only
//! `createBackupSnapshot` mutation, returning the on-disk path where
//! the server wrote the tarball.
//!
//! The restore path is intentionally not exposed via this CLI: a
//! restore needs the API stopped, the data directory wiped, and the
//! pg_restore run by an operator with shell access to the host.
//! Putting a one-button "restore" in a CLI talking to a live API
//! makes the foot-gun too easy. The restore runbook in
//! `docs/operator/disaster-recovery.md` is the sanctioned path.

use anyhow::Result;
use clap::Subcommand;
use serde_json::json;

use crate::client;

#[derive(Debug, Subcommand)]
pub enum BackupCmd {
    /// Trigger an on-demand snapshot of the live DB + storage root.
    /// Useful before a risky operation. Admin-only.
    Create,
}

pub fn run(cmd: BackupCmd) -> Result<()> {
    match cmd {
        BackupCmd::Create => create(),
    }
}

fn create() -> Result<()> {
    let (cli, _cfg) = client::authenticated()?;
    let data = cli.execute("mutation { createBackupSnapshot }", json!({}))?;
    let path = data["createBackupSnapshot"]
        .as_str()
        .unwrap_or("(no path returned)");
    println!("Snapshot written to {path}");
    Ok(())
}