81 lines
3.1 KiB
Rust
81 lines
3.1 KiB
Rust
//! `hivectl` — operator-facing host CLI for hyperhive.
|
|
//!
|
|
//! A thin client for the `hive-c0re` daemon: it speaks the host admin
|
|
//! socket protocol (`hive-host-sock`) and does NOT link the daemon crate.
|
|
//! Container lifecycle (`agent <name> <spawn|kill|rebuild|restart|choom|…>`,
|
|
//! `list-agents`, `stop` / `start`) and provisioning (`forge` /
|
|
//! `gateway`) all forward to the daemon, which owns the broker,
|
|
//! the credentials, and the provisioning logic — a running daemon is
|
|
//! required for those. A couple of verbs work off local host state
|
|
//! directly instead (`peer-config` reads the TLS CA), so
|
|
//! they don't need the socket. `agent <name> choom` execs into a container
|
|
//! rather than asking the daemon to do anything, but still uses the socket
|
|
//! for its "is this an agent?" pre-flight — that answer lives in a
|
|
//! directory only the daemon's user can read.
|
|
//!
|
|
//! One module per subcommand family (see the `mod` list below); `main` is
|
|
//! just the clap parse + the top-level dispatch match.
|
|
|
|
use anyhow::Result;
|
|
use clap::Parser;
|
|
|
|
mod cli;
|
|
/// The host admin socket client (`request`), split out so it lives with
|
|
/// hivectl rather than in the daemon crate.
|
|
mod client;
|
|
/// Rebuild-queue node progress rendering (`wait_for_nodes` + the spinner /
|
|
/// plain renderers), split out to keep this file manageable.
|
|
mod dag_progress;
|
|
use cli::{Cli, Cmd};
|
|
mod completions;
|
|
mod util;
|
|
use completions::generate_completions;
|
|
mod peer_config;
|
|
use peer_config::{peer_config, require_hive_domain};
|
|
mod agents;
|
|
mod choom;
|
|
mod watch;
|
|
use agents::{agents_list, run_agent};
|
|
mod power;
|
|
use power::{restart, start, stop};
|
|
mod subvol;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
tracing_subscriber::fmt()
|
|
.with_env_filter(
|
|
tracing_subscriber::EnvFilter::try_from_default_env()
|
|
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
|
|
)
|
|
.init();
|
|
let cli = Cli::parse();
|
|
let socket = cli.socket;
|
|
match cli.cmd {
|
|
Cmd::Agent { name, cmd } => run_agent(&socket, &name, cmd).await,
|
|
Cmd::ListAgents { json } => agents_list(&socket, json).await,
|
|
Cmd::PeerConfig => {
|
|
let domain = require_hive_domain(&socket).await?;
|
|
peer_config(&domain);
|
|
Ok(())
|
|
}
|
|
Cmd::Stop {
|
|
scope,
|
|
graceful,
|
|
no_wait,
|
|
} => stop(&socket, scope.to_scope(), graceful, no_wait).await,
|
|
Cmd::Start { scope, no_wait } => start(&socket, scope.to_scope(), no_wait).await,
|
|
Cmd::Restart { scope, graceful } => restart(&socket, scope.to_scope(), graceful).await,
|
|
Cmd::MarkdownDocs => {
|
|
// `show_footer(false)`: drop clap-markdown's own fixed
|
|
// "This document was generated automatically by..." footer —
|
|
// it's the one string in this doc that isn't ours to reword.
|
|
let options = clap_markdown::MarkdownOptions::new().show_footer(false);
|
|
print!("{}", clap_markdown::help_markdown_custom::<Cli>(&options));
|
|
Ok(())
|
|
}
|
|
Cmd::Completions { shell } => {
|
|
generate_completions(shell);
|
|
Ok(())
|
|
}
|
|
}
|
|
}
|