summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Jimmi HC2018-06-01 08:37:21 +0200
committerGravatar Jimmi HC2018-06-01 08:37:21 +0200
commit61f141ca6a5b6f3d7ab0eade8d6f8fbe0ac6a28e (patch)
tree98f75dfc4348b0b1a48288e4e998844bb6eca3cf /src
parentAdded example of how to parse Zig args with clap.core (diff)
downloadzig-clap-61f141ca6a5b6f3d7ab0eade8d6f8fbe0ac6a28e.tar.gz
zig-clap-61f141ca6a5b6f3d7ab0eade8d6f8fbe0ac6a28e.tar.xz
zig-clap-61f141ca6a5b6f3d7ab0eade8d6f8fbe0ac6a28e.zip
Core args now have a pointer to the param that the arg belongs to
Diffstat (limited to 'src')
-rw-r--r--src/core.zig22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/core.zig b/src/core.zig
index 22b5df2..8570220 100644
--- a/src/core.zig
+++ b/src/core.zig
@@ -123,12 +123,12 @@ pub fn Arg(comptime Id: type) type {
123 return struct { 123 return struct {
124 const Self = this; 124 const Self = this;
125 125
126 id: Id, 126 param: &const Param(Id),
127 value: ?[]const u8, 127 value: ?[]const u8,
128 128
129 pub fn init(id: Id, value: ?[]const u8) Self { 129 pub fn init(param: &const Param(Id), value: ?[]const u8) Self {
130 return Self { 130 return Self {
131 .id = id, 131 .param = param,
132 .value = value, 132 .value = value,
133 }; 133 };
134 } 134 }
@@ -287,7 +287,7 @@ pub fn Clap(comptime Id: type) type {
287 if (maybe_value != null) 287 if (maybe_value != null)
288 return error.DoesntTakeValue; 288 return error.DoesntTakeValue;
289 289
290 return Arg(Id).init(param.id, null); 290 return Arg(Id).init(param, null);
291 } 291 }
292 292
293 const value = blk: { 293 const value = blk: {
@@ -297,7 +297,7 @@ pub fn Clap(comptime Id: type) type {
297 break :blk (try clap.nextNoParse()) ?? return error.MissingValue; 297 break :blk (try clap.nextNoParse()) ?? return error.MissingValue;
298 }; 298 };
299 299
300 return Arg(Id).init(param.id, value); 300 return Arg(Id).init(param, value);
301 } 301 }
302 }, 302 },
303 ArgInfo.Kind.Short => { 303 ArgInfo.Kind.Short => {
@@ -315,7 +315,7 @@ pub fn Clap(comptime Id: type) type {
315 if (param.names.short) |_| continue; 315 if (param.names.short) |_| continue;
316 if (param.names.long) |_| continue; 316 if (param.names.long) |_| continue;
317 317
318 return Arg(Id).init(param.id, arg); 318 return Arg(Id).init(param, arg);
319 } 319 }
320 } 320 }
321 321
@@ -330,7 +330,7 @@ pub fn Clap(comptime Id: type) type {
330 const index = state.index; 330 const index = state.index;
331 const next_index = index + 1; 331 const next_index = index + 1;
332 332
333 for (clap.params) |param| { 333 for (clap.params) |*param| {
334 const short = param.names.short ?? continue; 334 const short = param.names.short ?? continue;
335 if (short != arg[index]) 335 if (short != arg[index])
336 continue; 336 continue;
@@ -348,18 +348,18 @@ pub fn Clap(comptime Id: type) type {
348 } 348 }
349 349
350 if (!param.takes_value) 350 if (!param.takes_value)
351 return Arg(Id).init(param.id, null); 351 return Arg(Id).init(param, null);
352 352
353 if (arg.len <= next_index) { 353 if (arg.len <= next_index) {
354 const value = (try clap.nextNoParse()) ?? return error.MissingValue; 354 const value = (try clap.nextNoParse()) ?? return error.MissingValue;
355 return Arg(Id).init(param.id, value); 355 return Arg(Id).init(param, value);
356 } 356 }
357 357
358 if (arg[next_index] == '=') { 358 if (arg[next_index] == '=') {
359 return Arg(Id).init(param.id, arg[next_index + 1..]); 359 return Arg(Id).init(param, arg[next_index + 1..]);
360 } 360 }
361 361
362 return Arg(Id).init(param.id, arg[next_index..]); 362 return Arg(Id).init(param, arg[next_index..]);
363 } 363 }
364 364
365 return error.InvalidArgument; 365 return error.InvalidArgument;