Skip to main content

parse_flags

Function parse_flags 

Source
pub fn parse_flags(args: &[String]) -> Result<BTreeMap<String, String>, String>
Expand description

Parse --key value, --key=value, and bare---key flag forms into a sorted map.

A flag with no value (either no following arg or the next arg starts with --) is recorded with the literal value "true". This is how boolean toggles like --detail are surfaced to subcommands without requiring the caller to type --detail true.

Sorted because deterministic flag handling makes the parsed structure independent of argv order, which in turn makes error messages stable across runs.

ยงErrors

Returns an error message string if a flag appears more than once or a positional argument is encountered.