diff options
Diffstat (limited to 'clap.zig')
| -rw-r--r-- | clap.zig | 21 |
1 files changed, 16 insertions, 5 deletions
| @@ -303,7 +303,7 @@ test "Diagnostic.report" { | |||
| 303 | pub fn Args(comptime Id: type, comptime params: []const Param(Id)) type { | 303 | pub 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. | ||
| 334 | pub fn parse( | 333 | pub 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. | ||
| 350 | pub 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 |