runtime-cli 0.1.0

Command-line client for managing git projects on Runtime
Documentation
//! Runtime CLI library entrypoint. Exposes `run(argv)` so integration
//! tests can drive the binary in-process and so the binary stays a
//! one-liner.
//!
//! Milestone 30. The CLI speaks the runtime GraphQL API via a thin
//! `reqwest::blocking` client. Auth lives in `~/.config/runtime/config.json`
//! and is provisioned by `runtime auth login`.

pub mod cli;
pub mod client;
pub mod commands;
pub mod config;
pub mod editor;
pub mod output;

use std::ffi::OsString;

use clap::{CommandFactory, Parser};

use crate::cli::{Cli, Command};

/// Parse `argv` and dispatch to the appropriate subcommand. Returns
/// `Ok(())` on success; subcommands surface errors via `anyhow`.
pub fn run<I, T>(argv: I) -> anyhow::Result<()>
where
    I: IntoIterator<Item = T>,
    T: Into<OsString> + Clone,
{
    let cli = Cli::try_parse_from(argv)?;
    match cli.command {
        Command::Auth(c) => commands::auth::run(c),
        Command::Repo(c) => commands::repo::run(c),
        Command::Issue(c) => commands::issue::run(c),
        Command::Pr(c) => commands::pr::run(c),
        Command::Run(c) => commands::run::run(c),
        Command::Org(c) => commands::org::run(c),
        Command::Release(c) => commands::release::run(c),
        Command::Api(c) => commands::api::run(c),
        Command::Backup(c) => commands::backup::run(c),
        Command::Completion { shell } => {
            // Issue #31 — emit the shell completion script. clap_complete
            // writes directly to a `Write`; we use stdout so the user can
            // pipe into the appropriate completion directory.
            let mut cmd = Cli::command();
            clap_complete::generate(
                clap_complete::Shell::from(shell),
                &mut cmd,
                "runtime",
                &mut std::io::stdout(),
            );
            Ok(())
        }
    }
}