Skip to main content

Module common_args

Module common_args 

Source
Expand description

Common CLI flag-scanning primitives.

Minimal, dependency-light helpers for hand-rolled argument parsers that do not want to pull in a full parser crate. Each helper is generic over the command name and flag being checked, so a consuming CLI supplies its own vocabulary (command names, flag spellings) and gets consistent error wording for free.

These are not a parser framework — they scan an already-split &[String] slice for a small, fixed set of shapes (no value, one required/optional value, reject-everything). A product CLI composes them per-subcommand.

Structs§

ArgParseError
An error produced while scanning CLI arguments.

Functions§

parse_bool_flag
Scan for a single boolean flag (present or absent), rejecting anything else including duplicates.
parse_optional_value_flag
Scan for an optional --flag value pair. Returns Ok(None) if the flag is absent, Ok(Some(value)) if present with a value, and an error for duplicates, missing values, or unexpected trailing arguments.
parse_required_value_flag
Scan for a --flag value pair the caller treats as required.
reject_args
Reject a subcommand that takes no arguments at all.