github Hejsil/zig-clap v0.2.0
zig-clap-0.2.0

latest releases: 0.9.1, 0.9.0, 0.8.0...
4 years ago

A new release of zig-clap for zig 0.6.0

Changes

Breaking

  • Now compilers with the zig 0.6.0 compiler.
  • Removes the clap.args.Iterator struct in favor of passing the argument iterator type directly to the different parsers.
    • These diffs show the difference between the two API's
      -var os_iter = clap.args.OsIterator.init(allocator);
      -const iter = &os_iter.iter;
      -defer os_iter.deinit();
      +var iter = clap.args.OsIterator.init(allocator);
      +defer iter.deinit();
      -var args = try clap.ComptimeClap([]const u8, params).parse(allocator, clap.args.OsIterator.Error, iter);
      +var args = try clap.ComptimeClap([]const u8, params).parse(allocator, clap.args.OsIterator, &iter);
    • clap.args.OsIterator now also consumes the arg[0] on init and has a field called exe where this argument is stored.
      • This puts this iterator more in line with how all the others are used.
  • clap.help and friends now take Param(Help) instead of Param([]const u8)
  • clap.help output is now slightly different:
    +    -d, --dd <V3>    Both option.
    -    -d, --dd=V3    Both option.
  • - and -- strings will now be interpreted as positional and not as arguments.

New

  • Adds clap.parseParam which takes a string similar to what clap.help emits for each parameter and returns a Param(Help)
    • Most users will find this API more convenient than initializing all the fields of Param themself:
       try clap.help(
           stderr,
      -    [_]clap.Param([]const u8){
      -        clap.Param([]const u8){
      -            .id = "Display this help and exit.",
      -            .names = clap.Names{ .short = 'h', .long = "help" },
      -        },
      -        clap.Param([]const u8){
      -            .id = "Output version information and exit.",
      -            .names = clap.Names{ .short = 'v', .long = "version" },
      -        },
      +    comptime [_]clap.Param(clap.Help){
      +        clap.parseParam("-h, --help     Display this help and exit.         ") catch unreachable,
      +        clap.parseParam("-v, --version  Output version information and exit.") catch unreachable,
          },
       );
  • Adds clap.parse. This is the new simplest way of using zig-clap.
  • Adds clap.usage. This function takes a slice of Param(Help) and a stream and prints a usage string based on the parameters passed.
    • Just like help this function has an Ex and Full version.

Don't miss a new zig-clap release

NewReleases is sending notifications on new releases.