Tags: modpm/cmd
Tags
Refined parser error messages for flags given `=` values (#14) This PR improves the clarity of argument parser messages when a boolean flag is incorrectly provided with a value using `=`. Previously, cases like `-f=val` or `--flag=value` would produce misleading messages such as ‘unknown option '-f'’ even if the flag exists. Now, the parser reports more precise messages: - `unexpected '=' for option '-f'` - `unexpected '=' for option '--flag'` - `unexpected '=' in combined short options '-ff'`
Count number of occurrences for flags (#11) `ParsedArgs` now stores the number of times boolean options (flags) were encountered in the command line. Example: `-vvvv` or `-v -v -v -v` will return `4` for `flag("-v")` as an unsigned integer. To check whether a flag is present (i.e. > 0 occurrences), use `hasFlag("-v")`. ## Breaking Change The old `bool flag(string | Flag)` method has been renamed to `bool hasFlag(string | Flag)`. The new method `uint flag(string | Flag)` is different and works as described in this PR and in the documentation.
Added support for grouping boolean options by short name (#10) Flags (boolean options) like `-a -b -c` can be grouped like `-abc` (in any order). Only works for flags/booleans and only for short options. Example: ```d new Program("cmd") .option("-f, --foo", "foo") .option("-b, --bar", "boo") .option("-B, --baz", "foo") // … ``` The flags can be set to true like so: ```sh cmd -fbB # equivalent to: cmd -f -b -B ``` When reading the parsed flags, they are still read separately: ``` auto foo = args.flag("-f"); auto bar = args.flag("-b"); auto baz = args.flag("-B"); ```