cli.rs
Overview
This file defines the command-line interface (CLI) argument parsing for the Acki-Nacki Block Manager component. It leverages the clap crate to provide a structured way to specify and validate runtime parameters required for the application. The primary purpose of this file is to declare the configurable inputs related to network endpoints and storage paths that the block manager will use to operate.
The file also defines a static constant LONG_VERSION that aggregates build metadata such as the package version, Git branch, commit, and build date/time, which is embedded into the CLI help/version output.
Detailed Explanation
Static Variable: LONG_VERSION
pub static LONG_VERSION: LazyLock<String>
Purpose: Holds a lazily initialized string that contains detailed version and build metadata.
Initialization: Uses
LazyLockto defer construction until first use, avoiding unnecessary computation at startup.Content: Composes a multi-line string including:
Cargo package version (
CARGO_PKG_VERSION)Git branch name (
BUILD_GIT_BRANCH)Git commit hash (
BUILD_GIT_COMMIT)Git commit date (
BUILD_GIT_DATE)Build time (
BUILD_TIME)
This information is injected at compile time via environment variables and used to display extended version information in CLI outputs.
Usage Example
your_binary --version
The output includes the detailed build info from LONG_VERSION.
Struct: Args
#[derive(Parser, Debug)]
pub struct Args
Derives:
Parser(fromclap) for automatic CLI argument parsing, andDebugfor debug printing.Attributes:
author: Automatically populated from Cargo metadata.long_version: Set toLONG_VERSIONfor extended version info display.about: Short description derived from crate metadata.long_about: None specified.
Fields
Field Name | Type | Description | CLI Argument / Env Variable | Default Value |
|---|---|---|---|---|
|
| URL of the HTTP/3 server for data streaming. Must use HTTPS with an explicit port specified. |
| Required (no default) |
|
| URL of the node HTTP endpoint for node communication. |
| Required (no default) |
|
| Socket address where the REST API will listen. |
|
|
|
| File system path to the SQLite database file used for storage. |
| Required (no default) |
All arguments can be set through CLI flags or environment variables.
rest_apihas a default value, others must be provided.
Example CLI Usage
your_binary \
--stream-src-url=https://example.com:443 \
--http-src-url=http://node-endpoint:8080 \
--rest-api=127.0.0.1:9000 \
--sqlite-path=/var/lib/db.sqlite
This command instructs the application to connect to the specified HTTP/3 server, node HTTP endpoint, bind the REST API to the given address, and use the given SQLite file for persistent storage.
Implementation Details
Uses
clap::Parsermacro to automatically generate command-line parsing code, reducing boilerplate and enforcing type safety.Uses
url::Urlfor validated URL parsing to ensure the URLs are properly structured and schemes match expectations.Uses
PathBuffor flexible and cross-platform filesystem path representation.Uses
LazyLockfor efficient, thread-safe lazy initialization of theLONG_VERSIONstring.Build metadata are injected at compile-time via environment variables defined in the build process, enabling traceability of the binary version.
Interaction with Other Parts of the System
The
Argsstruct serves as the central configuration input for the Acki-Nacki Block Manager's runtime behavior.Other modules consume the parsed CLI arguments to configure network connections (HTTP/3 stream source, node HTTP endpoint), REST API binding, and database access.
The URLs provided here are critical for establishing communication channels and data ingestion.
The SQLite path configures persistent storage used by the block manager to maintain state or cache data.
The version metadata in
LONG_VERSIONaugments CLI user experience by providing detailed build context useful for debugging and support.
Diagram: Structure of cli.rs
classDiagram
class Args {
+stream_src_url: Url
+http_src_url: Url
+rest_api: SocketAddr
+sqlite_path: PathBuf
}
class LONG_VERSION {
<<static>>
+String
}
Args ..> Url : uses
Args ..> SocketAddr : uses
Args ..> PathBuf : uses
LONG_VERSION <|-- LazyLock : initialized by
This diagram shows the primary data structure Args with its fields and the static LONG_VERSION lazy-initialized string, highlighting their relationships to standard types used for URL, socket address, and file paths.