Skip to content

Releases: Hejsil/zig-clap

zig-clap-0.2.0

18 Apr 15:14
Compare
Choose a tag to compare

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.

zig-clap-0.1.0

17 Jan 14:49
7800f4e
Compare
Choose a tag to compare

The first release of zig-clap.

Added

  • clap.args.Iterator.
    • The common interface for iterating over program arguments.
    • Used by the rest of the library.
  • clap.args.SliceIterator
    • An clap.args.Iterator which just iterates over a slice of strings.
  • clap.args.OsIterator
    • An clap.args.Iterator which wraps std.os.ArgIterator
    • It iterates over the program arguments the most memory efficient way on each platform.
  • clap.StreamingClap
    • A streaming argument parser. which, given a slice of parameters can parse arguments lazily.
    • This parse is used as a backend for other parsers.
  • clap.ComptimeClap
    • A parse which uses reflection to generate an efficient way of querying what parameters have been passed, and their values.
  • clap.help, clap.helpEx and clap.helpFull
    • Functions for pretty printing parameters.