zig-args icon indicating copy to clipboard operation
zig-args copied to clipboard

Help helper

Open ikskuh opened this issue 2 years ago • 0 comments

Implement means to allow the following to be used:

const CliOptions = struct {
  help: bool = true,
  output: ?[]const u8 = null,
  long: u32 = 0,
  pub const shorthands = .{
    .h = "help",
    .o = "output",
  };
  pub const meta = .{
    .summary = "[-h] [-o] [--long] <files>",
    .full_text = "This command prints the current time.",
    .option_docs = .{
      .help = "Prints this help.",
      .output = "Sets the output file.",
      .long = "Sets the number of lines."
    },
  }
};

// ...

if(cli.options.help) {
  try args_parser.printHelp(CliOptions, stdout);
  return 0;
}

where printHelp prints this:

current_exe_name [-h] [-o] [--long] <files>

This command prints the current time.

Options:
  -h, --help    Prints this help.
  -o, --output  Sets the output file.
      --long    Sets the number of lines

Compiler errors should be emitted when option_docs is not documentation all options.

summary, full_text and option_docs are optional fields of meta

ikskuh avatar Feb 15 '22 20:02 ikskuh