Releases: Hejsil/zig-clap
0.11.0
0.10.0
zig-clap release 0.10.0 which compiles and works for zig 0.14.0
Features
- Add
assignment_separatorstoclap.ParseOptions- This specifies the list of characters that can separate arguments. By default it is
"=" - Setting
assignment_separatorsto"=:"will make both--some-arg:valueand--some-arg=valuevalid argument syntax
- This specifies the list of characters that can separate arguments. By default it is
- Add
terminating_positionaltoclap.ParseOptions- This specifies the last positional index that
zig-clapwill parse before returning - This makes subcommands easier to parse with
zig-clap
- This specifies the last positional index that
- Add
clap.parsers.uint
Changes
clap.HelpOptions.max_widthis now unicode codepoint aware instead of just counting bytesclap.parseandclap.parseExnow supports parsing multiple parameters of different typesres.positionalsis now a tuple. Users ofzig-clap0.9.1needs to updateres.positionalstores.positionals[0]- This allows specifying
program <u8> <str>...and have@TypeOf(res.positionals[0]) == u8 and @TypeOf(res.positionals[1]) == []const []const u8 - There are some limits to how multiple positional parameters can be defined. See #153
0.9.1
0.9.0
0.8.0
0.7.0
zig-clap release 0.7.0 which compiles and works for zig 0.11.0
Changes
- Multiple occurrences of a flag are now counted.
- Fields for flag parameters are now type
u8instead ofbool. - Updating
zig-clapwill look something like this:
- if (arg_result.my_flag) + if (arg_result.my_flag != 0)
- Fields for flag parameters are now type
Added
zig-clapnow exposes itself as a module in the build script.- Support for multiple positional parameters.
0.6.0
zig-clap release 0.6.0 which compiles and works for zig 0.10.0
Changes
-
zig-clapis now under the MIT license instead of Unlicense #64 -
Refactor the
clap.ArgIteratorinterface to be the same interface asstd.process.ArgIterator -
clap.StreamingClaphas been moved toclap.streaming.Clap -
clap.parseParamcan now parse a parameter spanning multiple lines and is overall more robust than before. -
clap.parseandclap.parseExhas had their return type changed. Instead of returning a struct with.flag,.option,.optionsand.positionalsmethods, it now just returns a struct with fields for each parameter your program takes.clap.parseandclap.parseExtakes an additional argument, which use used to lookup the parser that should be used for each parameter.- Updating
zig-clapwill look something like this:
- var args = clap.parse(clap.Help, ¶ms, .{ + var args = clap.parse(clap.Help, ¶ms, clap.parsers.default, .{
- if (args.flag("--help")) + if (args.args.help) debug.print("--help\n", .{}); - if (args.option("--number")) |n| - debug.print("--number = {s}\n", .{n}); - for (args.options("--string")) |s| + if (args.args.number) |n| + debug.print("--number = {}\n", .{n}); + for (args.args.string) |s| debug.print("--string = {s}\n", .{s}); - for (args.positionals()) |pos| + for (args.positionals) |pos| debug.print("{s}\n", .{pos}); }
-
clap.helpandclap.usageare now generic and expect theIdinParam(Id)to provide getters fordescriptionandvalue. Usage ofclap.helpandclap.usagerequire the following change:- try help(stream, params); + try help(stream, clap.Help, params); - try usage(stream, params); + try usage(stream, clap.Help, params);
-
clap.helpnow also takes an option parameter that configures how the parameters should be formatted. You can leave it empty for a good default:- try help(stream, clap.Help, params); + try help(stream, clap.Help, params, .{});
Added
clap.parseParamExwhich is the same asclap.parseParam, but takes a pointer toendand sets that to the latest byte parsed before returning either an error or a value.clap.parseParamsandclap.parseParamsExwhich parse a string into a slice of multiple parameters.clap.parseParamsIntoSliceandclap.parseParamsIntoSliceExwhich parse a string into multiple parameters, which are stored into a slice passed in by the caller.clap.parseParamsIntoArrayListandclap.parseParamsIntoArrayListExwhich parse a string into multiple parameters, which are stored into anArrayListpassed in by the caller.clap.parseParamsComptimewhich parse a string into a slice of multiple parameters at compile time, returning a fixes size array.- This is the new "most convenient way" of specifying your parameters in
zig-clap. The following change is recommended, but not necessary.
- const params = comptime [_]clap.Param(clap.Help){ - clap.parseParam("-h, --help Display this help and exit.") catch unreachable, - clap.parseParam("-n, --number <usize> An option parameter, which takes a value.") catch unreachable, - clap.parseParam("-s, --string <str>... An option parameter which can be specified multiple times.") catch unreachable, - clap.parseParam("<str>...") catch unreachable, - }; + const params = comptime clap.parseParamsComptime( + \\-h, --help + \\ Display this help and exit. + \\-n, --number <usize> + \\ An option parameter, which takes a value. + \\-s, --string <str>... + \\ An option parameter which can be specified multiple times. + \\<str>... + \\ + );
- This is the new "most convenient way" of specifying your parameters in
Removed
clap.args.OsIterator. Usestd.process.ArgIteratorinsteadargs.ShellIterator. Usestd.process.ArgIteratorGeneralinsteadclap.ComptimeClap. Useclap.parseandclap.parseExinsteadclap.helpEx,clap.helpFull. Implement thedescriptionandvaluemethods on yourIdand useclap.helpinsteadclap.usageEx,clap.usageFull. Implement thedescriptionandvaluemethods on yourIdand useclap.helpinstead
Fixes
clap.usagenow prints many value positional parameters correctly as<file>...instead of<file>
0.5.0
0.4.1
0.4.0
zig-clap release 0.4.0 which compiles and works for zig 0.8.0.
Changes
Breaking
- Arguments after
--will now all be treated like positional arguments, even if they match something else.-a -bgives you the flagsaandb-a -- -bgives you the flagaand the positional argument-b.- This applies to both
clap.StreamingClapandclap.parse.
clap.parseandclap.parseExnow takes aParserOptions- This removes the
allocatoranddiagarguments from these functions and moves them into this new struct. - This change has been made to make it possible to introduce more options to these functions in the future without breaking the API again.
- This removes the
clap.StreamingClap.nextno longer takes thediagargument.- Instead, a
diagnosticfield have been added to this parser.
- Instead, a
- All enums have had their members names changed to
snake_case.
New
- Added new
args.ShellIterator(this might actually have been in0.3.0but it wasn't in the release notes 🤷)- This iterator takes a single string and splits it into arguments similarly to how
shorbashwould. - See the tests to get an idea as to how this iterator splits arguments.
- This iterator takes a single string and splits it into arguments similarly to how
- You should now be able to install
zig-clapthrough bothgyroandzigmodpackage managers.zig-clapcan also be found on theastrolabpackage repository.