Releases: Hejsil/zig-clap
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
u8
instead ofbool
. - Updating
zig-clap
will look something like this:
- if (arg_result.my_flag) + if (arg_result.my_flag != 0)
- Fields for flag parameters are now type
Added
zig-clap
now 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-clap
is now under the MIT license instead of Unlicense #64 -
Refactor the
clap.ArgIterator
interface to be the same interface asstd.process.ArgIterator
-
clap.StreamingClap
has been moved toclap.streaming.Clap
-
clap.parseParam
can now parse a parameter spanning multiple lines and is overall more robust than before. -
clap.parse
andclap.parseEx
has had their return type changed. Instead of returning a struct with.flag
,.option
,.options
and.positionals
methods, it now just returns a struct with fields for each parameter your program takes.clap.parse
andclap.parseEx
takes an additional argument, which use used to lookup the parser that should be used for each parameter.- Updating
zig-clap
will 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.help
andclap.usage
are now generic and expect theId
inParam(Id)
to provide getters fordescription
andvalue
. Usage ofclap.help
andclap.usage
require the following change:- try help(stream, params); + try help(stream, clap.Help, params); - try usage(stream, params); + try usage(stream, clap.Help, params);
-
clap.help
now 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.parseParamEx
which is the same asclap.parseParam
, but takes a pointer toend
and sets that to the latest byte parsed before returning either an error or a value.clap.parseParams
andclap.parseParamsEx
which parse a string into a slice of multiple parameters.clap.parseParamsIntoSlice
andclap.parseParamsIntoSliceEx
which parse a string into multiple parameters, which are stored into a slice passed in by the caller.clap.parseParamsIntoArrayList
andclap.parseParamsIntoArrayListEx
which parse a string into multiple parameters, which are stored into anArrayList
passed in by the caller.clap.parseParamsComptime
which 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.ArgIterator
insteadargs.ShellIterator
. Usestd.process.ArgIteratorGeneral
insteadclap.ComptimeClap
. Useclap.parse
andclap.parseEx
insteadclap.helpEx
,clap.helpFull
. Implement thedescription
andvalue
methods on yourId
and useclap.help
insteadclap.usageEx
,clap.usageFull
. Implement thedescription
andvalue
methods on yourId
and useclap.help
instead
Fixes
clap.usage
now 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 -b
gives you the flagsa
andb
-a -- -b
gives you the flaga
and the positional argument-b
.- This applies to both
clap.StreamingClap
andclap.parse
.
clap.parse
andclap.parseEx
now takes aParserOptions
- This removes the
allocator
anddiag
arguments 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.next
no longer takes thediag
argument.- Instead, a
diagnostic
field 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.0
but it wasn't in the release notes 🤷)- This iterator takes a single string and splits it into arguments similarly to how
sh
orbash
would. - 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-clap
through bothgyro
andzigmod
package managers.zig-clap
can also be found on theastrolab
package repository.
zig-clap-0.3.0
A new release of zig-clap
for zig 0.7.0
Changes
Breaking
- Now compilers with the
zig 0.7.0
compiler. clap.parse
now supports capturing multiple options.- To get multiple options your parameters need to have the
take_values
field beclap.Values.Many
.clap.parseParam
has syntax for this:clap.parseParam("-s, --ss <V>... This is a help message")
.
- The
options
function can be called to get a slice of all options passed the parameter.
- To get multiple options your parameters need to have the
- All parsers now take an extra diagnostic parameter, which can be used to report more useful error messages.
- The
clap.Diagnostic
struct has areport
method which prints a simple English error message.- Use this as a reference if you want to implement error reporting yourself.
null
can be pass if the caller does not care about this extra information.
- The
New
clap.parseParam
now supports parsing positional parameter help messages.- Syntax is as follows:
clap.parseParam("<P> This is a positional parameter")
.
- Syntax is as follows:
clap.args.OsIterator
now returns null-terminated strings.
Fixes
- No longer gives compile error for 32 bit targets (#23)
zig-clap-0.2.0
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 thearg[0]
oninit
and has a field calledexe
where this argument is stored.- This puts this iterator more in line with how all the others are used.
- These diffs show the difference between the two API's
clap.help
and friends now takeParam(Help)
instead ofParam([]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 whatclap.help
emits for each parameter and returns aParam(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, }, );
- Most users will find this API more convenient than initializing all the fields of
- Adds
clap.parse
. This is the new simplest way of usingzig-clap
. - Adds
clap.usage
. This function takes a slice ofParam(Help)
and a stream and prints a usage string based on the parameters passed.- Just like
help
this function has anEx
andFull
version.
- Just like