pub fn parse_with_version<T: FromArgMatches>(
command: Command,
version: &ColorfulVersion,
) -> Result<T, Error>Expand description
Helper function to parse command-line arguments with version handling
This function should be used instead of directly calling get_matches().
If the version flag is found, it prints the colorful version and exits.
ยงExamples
use clap::{Parser, CommandFactory};
use clap_version_flag::{colorful_version, parse_with_version};
#[derive(Parser)]
struct Cli {
input: String,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let version = colorful_version!();
let cli: Cli = parse_with_version(Cli::command(), &version)?;
// Normal program execution continues here
Ok(())
}