diff options
Diffstat (limited to '')
| -rw-r--r-- | README.md | 12 | ||||
| -rw-r--r-- | build.zig | 3 | ||||
| -rw-r--r-- | clap.zig | 4 |
3 files changed, 11 insertions, 8 deletions
| @@ -46,9 +46,9 @@ pub fn main() !void { | |||
| 46 | if (args.flag("--help")) | 46 | if (args.flag("--help")) |
| 47 | debug.warn("--help\n", .{}); | 47 | debug.warn("--help\n", .{}); |
| 48 | if (args.option("--number")) |n| | 48 | if (args.option("--number")) |n| |
| 49 | debug.warn("--number = {}\n", .{ n }); | 49 | debug.warn("--number = {}\n", .{n}); |
| 50 | for (args.positionals()) |pos| | 50 | for (args.positionals()) |pos| |
| 51 | debug.warn("{}\n", .{ pos }); | 51 | debug.warn("{}\n", .{pos}); |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | ``` | 54 | ``` |
| @@ -125,9 +125,9 @@ pub fn main() !void { | |||
| 125 | if (args.flag("--help")) | 125 | if (args.flag("--help")) |
| 126 | debug.warn("--help\n", .{}); | 126 | debug.warn("--help\n", .{}); |
| 127 | if (args.option("--number")) |n| | 127 | if (args.option("--number")) |n| |
| 128 | debug.warn("--number = {}\n", .{ n }); | 128 | debug.warn("--number = {}\n", .{n}); |
| 129 | for (args.positionals()) |pos| | 129 | for (args.positionals()) |pos| |
| 130 | debug.warn("{}\n", .{ pos }); | 130 | debug.warn("{}\n", .{pos}); |
| 131 | } | 131 | } |
| 132 | 132 | ||
| 133 | ``` | 133 | ``` |
| @@ -179,12 +179,12 @@ pub fn main() !void { | |||
| 179 | // arg.param will point to the parameter which matched the argument. | 179 | // arg.param will point to the parameter which matched the argument. |
| 180 | switch (arg.param.id) { | 180 | switch (arg.param.id) { |
| 181 | 'h' => debug.warn("Help!\n", .{}), | 181 | 'h' => debug.warn("Help!\n", .{}), |
| 182 | 'n' => debug.warn("--number = {}\n", .{ arg.value.? }), | 182 | 'n' => debug.warn("--number = {}\n", .{arg.value.?}), |
| 183 | 183 | ||
| 184 | // arg.value == null, if arg.param.takes_value == false. | 184 | // arg.value == null, if arg.param.takes_value == false. |
| 185 | // Otherwise, arg.value is the value passed with the argument, such as "-a=10" | 185 | // Otherwise, arg.value is the value passed with the argument, such as "-a=10" |
| 186 | // or "-a 10". | 186 | // or "-a 10". |
| 187 | 'f' => debug.warn("{}\n", .{ arg.value.? }), | 187 | 'f' => debug.warn("{}\n", .{arg.value.?}), |
| 188 | else => unreachable, | 188 | else => unreachable, |
| 189 | } | 189 | } |
| 190 | } | 190 | } |
| @@ -6,6 +6,7 @@ const Builder = std.build.Builder; | |||
| 6 | 6 | ||
| 7 | pub fn build(b: *Builder) void { | 7 | pub fn build(b: *Builder) void { |
| 8 | const mode = b.standardReleaseOptions(); | 8 | const mode = b.standardReleaseOptions(); |
| 9 | const target = b.standardTargetOptions(.{}); | ||
| 9 | 10 | ||
| 10 | const fmt_step = b.addFmt(&[_][]const u8{ | 11 | const fmt_step = b.addFmt(&[_][]const u8{ |
| 11 | "build.zig", | 12 | "build.zig", |
| @@ -20,6 +21,7 @@ pub fn build(b: *Builder) void { | |||
| 20 | 21 | ||
| 21 | const tests = b.addTest("clap.zig"); | 22 | const tests = b.addTest("clap.zig"); |
| 22 | tests.setBuildMode(test_mode); | 23 | tests.setBuildMode(test_mode); |
| 24 | tests.setTarget(target); | ||
| 23 | tests.setNamePrefix(mode_str ++ " "); | 25 | tests.setNamePrefix(mode_str ++ " "); |
| 24 | 26 | ||
| 25 | const test_step = b.step("test-" ++ mode_str, "Run all tests in " ++ mode_str ++ "."); | 27 | const test_step = b.step("test-" ++ mode_str, "Run all tests in " ++ mode_str ++ "."); |
| @@ -39,6 +41,7 @@ pub fn build(b: *Builder) void { | |||
| 39 | const example = b.addExecutable(example_name, "example/" ++ example_name ++ ".zig"); | 41 | const example = b.addExecutable(example_name, "example/" ++ example_name ++ ".zig"); |
| 40 | example.addPackagePath("clap", "clap.zig"); | 42 | example.addPackagePath("clap", "clap.zig"); |
| 41 | example.setBuildMode(mode); | 43 | example.setBuildMode(mode); |
| 44 | example.setTarget(target); | ||
| 42 | example.install(); | 45 | example.install(); |
| 43 | example_step.dependOn(&example.step); | 46 | example_step.dependOn(&example.step); |
| 44 | } | 47 | } |
| @@ -290,7 +290,7 @@ pub fn helpFull( | |||
| 290 | var counting_stream = io.countingOutStream(io.null_out_stream); | 290 | var counting_stream = io.countingOutStream(io.null_out_stream); |
| 291 | try printParam(counting_stream.outStream(), Id, param, Error, context, valueText); | 291 | try printParam(counting_stream.outStream(), Id, param, Error, context, valueText); |
| 292 | if (res < counting_stream.bytes_written) | 292 | if (res < counting_stream.bytes_written) |
| 293 | res = counting_stream.bytes_written; | 293 | res = @intCast(usize, counting_stream.bytes_written); |
| 294 | } | 294 | } |
| 295 | 295 | ||
| 296 | break :blk res; | 296 | break :blk res; |
| @@ -303,7 +303,7 @@ pub fn helpFull( | |||
| 303 | var counting_stream = io.countingOutStream(stream); | 303 | var counting_stream = io.countingOutStream(stream); |
| 304 | try stream.print("\t", .{}); | 304 | try stream.print("\t", .{}); |
| 305 | try printParam(counting_stream.outStream(), Id, param, Error, context, valueText); | 305 | try printParam(counting_stream.outStream(), Id, param, Error, context, valueText); |
| 306 | try stream.writeByteNTimes(' ', max_spacing - counting_stream.bytes_written); | 306 | try stream.writeByteNTimes(' ', max_spacing - @intCast(usize, counting_stream.bytes_written)); |
| 307 | try stream.print("\t{}\n", .{try helpText(context, param)}); | 307 | try stream.print("\t{}\n", .{try helpText(context, param)}); |
| 308 | } | 308 | } |
| 309 | } | 309 | } |