summaryrefslogtreecommitdiff
path: root/clap.zig
diff options
context:
space:
mode:
authorGravatar Jimmi Holst Christensen2020-11-10 18:53:57 +0100
committerGravatar Jimmi Holst Christensen2020-11-10 18:53:57 +0100
commitb7e6ebf36e2ac4314e6bff65f1d64466ea82a18a (patch)
treef979a760149f4c7a2d9b9113a872d8d7e6d56bef /clap.zig
parentUpdate ci to use 0.7.0 (diff)
downloadzig-clap-b7e6ebf36e2ac4314e6bff65f1d64466ea82a18a.tar.gz
zig-clap-b7e6ebf36e2ac4314e6bff65f1d64466ea82a18a.tar.xz
zig-clap-b7e6ebf36e2ac4314e6bff65f1d64466ea82a18a.zip
Deprecate ComptimeClap in favor of parseExv0.3.0
Diffstat (limited to 'clap.zig')
-rw-r--r--clap.zig21
1 files changed, 16 insertions, 5 deletions
diff --git a/clap.zig b/clap.zig
index 8624c88..4548a48 100644
--- a/clap.zig
+++ b/clap.zig
@@ -303,7 +303,7 @@ test "Diagnostic.report" {
303pub fn Args(comptime Id: type, comptime params: []const Param(Id)) type { 303pub fn Args(comptime Id: type, comptime params: []const Param(Id)) type {
304 return struct { 304 return struct {
305 arena: std.heap.ArenaAllocator, 305 arena: std.heap.ArenaAllocator,
306 clap: ComptimeClap(Id, args.OsIterator, params), 306 clap: ComptimeClap(Id, params),
307 exe_arg: ?[]const u8, 307 exe_arg: ?[]const u8,
308 308
309 pub fn deinit(a: *@This()) void { 309 pub fn deinit(a: *@This()) void {
@@ -329,8 +329,7 @@ pub fn Args(comptime Id: type, comptime params: []const Param(Id)) type {
329 }; 329 };
330} 330}
331 331
332/// Parses the command line arguments passed into the program based on an 332/// Same as `parseEx` but uses the `args.OsIterator` by default.
333/// array of `Param`s.
334pub fn parse( 333pub fn parse(
335 comptime Id: type, 334 comptime Id: type,
336 comptime params: []const Param(Id), 335 comptime params: []const Param(Id),
@@ -338,8 +337,7 @@ pub fn parse(
338 diag: ?*Diagnostic, 337 diag: ?*Diagnostic,
339) !Args(Id, params) { 338) !Args(Id, params) {
340 var iter = try args.OsIterator.init(allocator); 339 var iter = try args.OsIterator.init(allocator);
341 const Clap = ComptimeClap(Id, args.OsIterator, params); 340 const clap = try parseEx(Id, params, allocator, &iter, diag);
342 const clap = try Clap.parse(allocator, &iter, diag);
343 return Args(Id, params){ 341 return Args(Id, params){
344 .arena = iter.arena, 342 .arena = iter.arena,
345 .clap = clap, 343 .clap = clap,
@@ -347,6 +345,19 @@ pub fn parse(
347 }; 345 };
348} 346}
349 347
348/// Parses the command line arguments passed into the program based on an
349/// array of `Param`s.
350pub fn parseEx(
351 comptime Id: type,
352 comptime params: []const Param(Id),
353 allocator: *mem.Allocator,
354 iter: anytype,
355 diag: ?*Diagnostic,
356) !ComptimeClap(Id, params) {
357 const Clap = ComptimeClap(Id, params);
358 return try Clap.parse(allocator, iter, diag);
359}
360
350/// Will print a help message in the following format: 361/// Will print a help message in the following format:
351/// -s, --long <valueText> helpText 362/// -s, --long <valueText> helpText
352/// -s, helpText 363/// -s, helpText