Skip to main content

runtime_cli/
lib.rs

1//! Runtime CLI library entrypoint. Exposes `run(argv)` so integration
2//! tests can drive the binary in-process and so the binary stays a
3//! one-liner.
4//!
5//! Milestone 30. The CLI speaks the runtime GraphQL API via a thin
6//! `reqwest::blocking` client. Auth lives in `~/.config/runtime/config.json`
7//! and is provisioned by `runtime auth login`.
8
9pub mod cli;
10pub mod client;
11pub mod commands;
12pub mod config;
13pub mod editor;
14pub mod output;
15
16use std::ffi::OsString;
17
18use clap::{CommandFactory, Parser};
19
20use crate::cli::{Cli, Command};
21
22/// Parse `argv` and dispatch to the appropriate subcommand. Returns
23/// `Ok(())` on success; subcommands surface errors via `anyhow`.
24pub fn run<I, T>(argv: I) -> anyhow::Result<()>
25where
26    I: IntoIterator<Item = T>,
27    T: Into<OsString> + Clone,
28{
29    let cli = Cli::try_parse_from(argv)?;
30    match cli.command {
31        Command::Auth(c) => commands::auth::run(c),
32        Command::Repo(c) => commands::repo::run(c),
33        Command::Issue(c) => commands::issue::run(c),
34        Command::Pr(c) => commands::pr::run(c),
35        Command::Run(c) => commands::run::run(c),
36        Command::Org(c) => commands::org::run(c),
37        Command::Release(c) => commands::release::run(c),
38        Command::Api(c) => commands::api::run(c),
39        Command::Backup(c) => commands::backup::run(c),
40        Command::Completion { shell } => {
41            // Issue #31 — emit the shell completion script. clap_complete
42            // writes directly to a `Write`; we use stdout so the user can
43            // pipe into the appropriate completion directory.
44            let mut cmd = Cli::command();
45            clap_complete::generate(
46                clap_complete::Shell::from(shell),
47                &mut cmd,
48                "runtime",
49                &mut std::io::stdout(),
50            );
51            Ok(())
52        }
53    }
54}