cli.rs
Overview
This file defines the command-line interface (CLI) for the Acki Nacki proxy publisher application. It uses the clap crate to parse command-line arguments and provides metadata about the build version and environment through a lazily initialized static string. The primary purpose of this file is to expose user-configurable parameters for the proxy publisher, specifically the endpoint URL to which the proxy connects or publishes.
Detailed Explanation
Static Variable: LONG_VERSION
pub static LONG_VERSION: LazyLock<String>
Purpose:
Holds a detailed multi-line string describing the current build version and related Git metadata for the application.Initialization:
UsesLazyLockto defer the construction of the string until it is first accessed, improving startup performance. The string is constructed by interpolating environment variables defined at compile time:CARGO_PKG_VERSION: The version of the package.BUILD_GIT_BRANCH: Git branch name at build time.BUILD_GIT_COMMIT: Git commit hash.BUILD_GIT_DATE: Date of the Git commit.BUILD_TIME: Build timestamp.
Usage:
This static string is used as the long version string shown in CLI help output or version commands, allowing users to see detailed build information.
Struct: CliArgs
#[derive(Parser, Debug)]
#[command(author, long_version = &**LONG_VERSION, about, long_about = None)]
pub struct CliArgs {
#[arg(short, long, default_value = "localhost:8090")]
pub endpoint: Url,
}
Purpose:
Defines the command-line arguments accepted by the Acki Nacki proxy publisher.Attributes:
#[derive(Parser, Debug)]enables automatic parsing of CLI arguments and implements theDebugtrait for convenient printing.#[command(...)]provides metadata to the CLI app:author: Automatically populated from Cargo.toml.long_version: Uses theLONG_VERSIONstatic for detailed version info.about: Brief description of the CLI (implicitly from Cargo metadata).long_about: Set toNone(no extended description).
Fields:
endpoint(type:Urlfrom theurlcrate):Represents the network endpoint of the proxy publisher.
Command line flags:
-eor--endpoint.Default value:
"localhost:8090".This field is parsed as a
Urltype, ensuring valid URL format input.
Example Usage:
acki-nacki-proxy-publisher --endpoint http://example.com:9000
This command runs the proxy publisher with the endpoint set to http://example.com:9000.
Implementation Details
Lazy Initialization:
LazyLockis used to efficiently initializeLONG_VERSIONonly once, on first use. This avoids unnecessary computation if the version info is never requested.Environment Variable Injection:
The build metadata strings are injected at compile time using the Rustenv!macro. This tightly couples build information with the CLI for diagnostics and debugging purposes.URL Parsing:
By using theUrltype from theurlcrate for theendpointargument, the CLI ensures that only valid URLs are accepted, providing early error detection.
Interaction with Other Parts of the System
This CLI module provides the entry point for configuring the proxy publisher behavior through command-line arguments.
The
CliArgsstruct is typically instantiated early in the application'smainfunction or initialization sequence to parse user input.The
endpointURL is passed downstream to networking or proxy modules responsible for establishing connections or publishing data.The
LONG_VERSIONstring is used in help/version commands, enabling users and developers to verify the exact build and commit information, useful for troubleshooting or support.
Mermaid Diagram
classDiagram
class CliArgs {
+endpoint: Url
}
class LONG_VERSION {
<<static>>
+String value
}
CliArgs ..> Url : uses
LONG_VERSION ..> String : contains
The diagram shows the main data structure CliArgs with its endpoint property of type Url. The LONG_VERSION static holds a detailed version string. The arrows indicate usage or containment relationships.