hyperi_rustlib/cli/mod.rs
1// Project: hyperi-rustlib
2// File: src/cli/mod.rs
3// Purpose: Standard CLI framework for DFE services
4// Language: Rust
5//
6// License: BUSL-1.1
7// Copyright: (c) 2026 HYPERI PTY LIMITED
8
9//! Standard CLI framework for DFE Rust services.
10//!
11//! Provides the 80% of CLI boilerplate that every DFE service needs:
12//! config path, log level/format, metrics address, version, config-check.
13//! Apps provide the 20% (config type, service logic) via the [`DfeApp`] trait.
14//!
15//! ## Quick Start
16//!
17//! ```rust,ignore
18//! use clap::Parser;
19//! use hyperi_rustlib::cli::{CommonArgs, DfeApp, CliError, StandardCommand, VersionInfo, run_app};
20//!
21//! #[derive(Parser)]
22//! #[command(name = "dfe-loader", version)]
23//! struct App {
24//! #[command(flatten)]
25//! common: CommonArgs,
26//!
27//! #[command(subcommand)]
28//! command: Option<StandardCommand>,
29//! }
30//!
31//! impl DfeApp for App {
32//! type Config = MyConfig;
33//!
34//! fn name(&self) -> &str { "dfe-loader" }
35//! fn env_prefix(&self) -> &str { "DFE_LOADER" }
36//! fn version_info(&self) -> VersionInfo {
37//! VersionInfo::new("dfe-loader", env!("CARGO_PKG_VERSION"))
38//! }
39//! fn common_args(&self) -> &CommonArgs { &self.common }
40//! fn command(&self) -> Option<&StandardCommand> { self.command.as_ref() }
41//! fn load_config(&self, path: Option<&str>) -> Result<MyConfig, CliError> { todo!() }
42//! async fn run_service(&self, config: MyConfig) -> Result<(), CliError> { todo!() }
43//! }
44//!
45//! #[tokio::main]
46//! async fn main() {
47//! let app = App::parse();
48//! if let Err(e) = run_app(app).await {
49//! eprintln!("fatal: {e}");
50//! std::process::exit(1);
51//! }
52//! }
53//! ```
54
55mod args;
56mod commands;
57mod error;
58pub mod output;
59mod version;
60
61// DfeApp + ServiceRuntime require the full service infrastructure stack
62// (MetricsManager, MemoryGuard, ScalingPressure, AdaptiveWorkerPool).
63// Gated behind `cli-service`. Bare `cli` exposes only the clap types.
64#[cfg(feature = "cli-service")]
65mod app;
66#[cfg(feature = "cli-service")]
67mod runtime;
68
69pub use args::CommonArgs;
70pub use commands::StandardCommand;
71pub use error::CliError;
72pub use version::VersionInfo;
73
74#[cfg(feature = "cli-service")]
75pub use app::{DfeApp, run_app};
76#[cfg(feature = "cli-service")]
77pub use runtime::ServiceRuntime;
78
79#[cfg(feature = "top")]
80pub use commands::TopArgs;