ikskuh / zig-args

Simple-to-use argument parser with struct-based config
MIT License
243 stars 27 forks source link

Add support for yes/no booleans #54

Open ikskuh opened 6 months ago

ikskuh commented 6 months ago

Some programs require "troolean" options that can have a default, but also be forced to true and false.

We can either implement it as a special case for ?bool or provide a custom type for this:


const Trinary = enum { unset, false, true };

var cli = parse(struct {
    @"emit-bin": ?bool = null, // --emit-bin and --no-emit-bin
    @"emit-bin": args.Trinary = .unset, // --emit-bin and --no-emit-bin
}, …);