n0s4 / flags

An effortless command-line argument parser for Zig.
MIT License
33 stars 2 forks source link

Feature request: show default values in help text #11

Open kj4tmp opened 1 day ago

kj4tmp commented 1 day ago

Thanks for making this awesome library!!

Would it be possible to show the default values in the help menu?

For example:

// CLI options
const Flags = struct {
    // Optional description of the program.
    pub const description =
        \\The GatorCAT CLI.
    ;
    // sub commands
    command: union(enum) {
        // scan bus
        scan: struct {
            ifname: []const u8,
            recv_timeout_us: u32 = 10000,
            eeprom_timeout_us: u32 = 10000,
            pub const descriptions = .{
                .ifname = "Network interface to use for the bus scan.",
                .recv_timeout_us = "Frame receive timeout in microseconds.",
                .eeprom_timeout_us = "SII EEPROM timeout in microseconds.",
            };
        },
    },
};

Produces:

gatorcat scan -h
Usage: gatorcat scan --ifname <ifname> [--recv-timeout-us <recv-timeout-us>]
                     [--eeprom-timeout-us <eeprom-timeout-us>] [-h | --help]

Options:

  --ifname            Network interface to use for the bus scan.
  --recv-timeout-us   Frame receive timeout in microseconds.
  --eeprom-timeout-us SII EEPROM timeout in microseconds.
  -h, --help          Show this help and exit

The help text could perhaps say that <eeprom-timeout-us> defaults to 10000 somewhere.

kj4tmp commented 1 day ago

If you like this idea and have a way you think it should look exactly, I could make an attempt at a PR.