Skip to main content

Module cli

Module cli 

Source
Available on crate feature cli only.
Expand description

Standard CLI framework for DFE Rust services.

Provides the 80% of CLI boilerplate that every DFE service needs: config path, log level/format, metrics address, version, config-check. Apps provide the 20% (config type, service logic) via the DfeApp trait.

§Quick Start

use clap::Parser;
use hyperi_rustlib::cli::{CommonArgs, DfeApp, CliError, StandardCommand, VersionInfo, run_app};

#[derive(Parser)]
#[command(name = "dfe-loader", version)]
struct App {
    #[command(flatten)]
    common: CommonArgs,

    #[command(subcommand)]
    command: Option<StandardCommand>,
}

impl DfeApp for App {
    type Config = MyConfig;

    fn name(&self) -> &str { "dfe-loader" }
    fn env_prefix(&self) -> &str { "DFE_LOADER" }
    fn version_info(&self) -> VersionInfo {
        VersionInfo::new("dfe-loader", env!("CARGO_PKG_VERSION"))
    }
    fn common_args(&self) -> &CommonArgs { &self.common }
    fn command(&self) -> Option<&StandardCommand> { self.command.as_ref() }
    fn load_config(&self, path: Option<&str>) -> Result<MyConfig, CliError> { todo!() }
    async fn run_service(&self, config: MyConfig) -> Result<(), CliError> { todo!() }
}

#[tokio::main]
async fn main() {
    let app = App::parse();
    if let Err(e) = run_app(app).await {
        eprintln!("fatal: {e}");
        std::process::exit(1);
    }
}

Modules§

output
Output formatting helpers for CLI tools.

Structs§

CommonArgs
Standard CLI arguments for DFE services.
ServiceRuntime
Pre-built service infrastructure. Created by run_app() before run_service().
VersionInfo
Service version information.

Enums§

CliError
Errors from CLI operations.
StandardCommand
Standard subcommands provided by rustlib.

Traits§

DfeApp
Trait for DFE service applications.

Functions§

run_app
Drive the standard DFE service lifecycle.