Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Entry Point and Utilities

Files: main.rs, utils.rs, commands/mod.rs Crate: kinetic-cli | Stage: 14


main.rs — Dispatch

main() parses the Commands enum with clap, loads KineticConfig, then dispatches. Two patterns:

Commands that need the daemon API — build the authenticated HTTP client first:

#![allow(unused)]
fn main() {
let client = utils::build_client(30)?;
commands::name::handle_name_command(cmd, &config, &client).await?;
}

Commands that manage sub-binaries — call handle_service_command:

#![allow(unused)]
fn main() {
Commands::Dns { cmd } => {
    let bin = format!("{}-dns", NETWORK_ID);
    handle_service_command(&bin, cmd, true).await?; // true = needs sudo
}
}

Note

Commands::Setup and Commands::Seed don’t need the client (they work fully offline — no daemon required).

verify_cli() test: uses clap’s debug_assert() to catch structural bugs (missing required args, conflicting flags) at test time.

#![allow(unused)]
fn main() {
-> See: `kinetic-cli/src/main.rs` — Lines 100–111
}

utils.rs — Three Helpers

build_client(timeout_secs) -> Result<Client>

Important

Reads <base_dir>/tokens/admin.token, inserts it as Authorization: Bearer <token> in default headers, builds a reqwest::Client with the given timeout. Called once per command invocation — not reused across commands.

#![allow(unused)]
fn main() {
-> See: `kinetic-cli/src/utils.rs` — Lines 68–80
}

parse_and_format_api_error(context, status, body) -> String

Tries serde_json::from_str::<kinetic_core::ApiError>(body). On success: "[<code>] <context>: <detail>". On fail (HTML error pages, plain text): "<context>: HTTP <status> - <body>". Used everywhere an API call can return a non-2xx.

#![allow(unused)]
fn main() {
-> See: `kinetic-cli/src/utils.rs` — Lines 13–23
}

save_zone_file(fqdn, zone) -> Result<()>

Validates the apex name via is_valid_apex_name(), then writes <zones_dir>/<fqdn>.json as pretty-printed JSON. Used by name register and name publish to cache the zone locally.

#![allow(unused)]
fn main() {
-> See: `kinetic-cli/src/utils.rs` — Lines 32–47
}

commands/mod.rs — The Commands Enum

All top-level subcommands live here. Daemon, Host, Node, Dns, and Pac all share the same ServiceCommands sub-enum — same 7 lifecycle ops (install, uninstall, run, start, stop, status, logs) delegated to different binaries.

#![allow(unused)]
fn main() {
-> See: `kinetic-cli/src/commands/mod.rs` — Lines 16–72
}