Skip to main content

parse_args

Function parse_args 

Source
pub fn parse_args(tool_version: &str, long_version: &str) -> Cli
Expand description

Parse process args and produce a Cli. Splits in half from run so the binary main.rs can consult cli.input.src (config-aware) before constructing its LcovParser (which needs the source root at construction time per the LCOV adapter’s path-stripping invariant). run then consumes the parsed Cli directly.

tool_version (e.g. crap4rs’s 0.4.0) and long_version (e.g. 0.4.0 (abc1234 2026-05-09)) are spliced into clap’s help and --version output at runtime so the binary’s build-script metadata reaches the help text — the derive macro’s version reads CARGO_PKG_VERSION at lib-crate compile time (crap-core’s 0.1.0), and CRAP4RS_LONG_VERSION is only set during the binary’s compile.

clap::Command::{version,long_version} take IntoResettable<Str> which implements From<&'static str> but not From<String>. The strings live for the program’s lifetime, so leaking once at startup is the cheapest path that satisfies clap’s expected lifetime. The leak is fixed-size and one-shot.