diff options
Diffstat (limited to '')
| -rw-r--r-- | README.md | 24 | ||||
| -rw-r--r-- | example/comptime-clap.zig | 8 | ||||
| -rw-r--r-- | example/streaming-clap.zig | 4 | ||||
| -rw-r--r-- | src/comptime.zig | 19 |
4 files changed, 15 insertions, 40 deletions
| @@ -25,9 +25,7 @@ const clap = @import("clap"); | |||
| 25 | const debug = std.debug; | 25 | const debug = std.debug; |
| 26 | 26 | ||
| 27 | pub fn main() !void { | 27 | pub fn main() !void { |
| 28 | var direct_allocator = std.heap.DirectAllocator.init(); | 28 | const allocator = std.heap.direct_allocator; |
| 29 | const allocator = &direct_allocator.allocator; | ||
| 30 | defer direct_allocator.deinit(); | ||
| 31 | 29 | ||
| 32 | // First we specify what parameters our program can take. | 30 | // First we specify what parameters our program can take. |
| 33 | const params = [_]clap.Param(u8){ | 31 | const params = [_]clap.Param(u8){ |
| @@ -90,13 +88,7 @@ const clap = @import("clap"); | |||
| 90 | const debug = std.debug; | 88 | const debug = std.debug; |
| 91 | 89 | ||
| 92 | pub fn main() !void { | 90 | pub fn main() !void { |
| 93 | const stdout_file = try std.io.getStdOut(); | 91 | const allocator = std.heap.direct_allocator; |
| 94 | var stdout_out_stream = stdout_file.outStream(); | ||
| 95 | const stdout = &stdout_out_stream.stream; | ||
| 96 | |||
| 97 | var direct_allocator = std.heap.DirectAllocator.init(); | ||
| 98 | const allocator = &direct_allocator.allocator; | ||
| 99 | defer direct_allocator.deinit(); | ||
| 100 | 92 | ||
| 101 | // First we specify what parameters our program can take. | 93 | // First we specify what parameters our program can take. |
| 102 | const params = [_]clap.Param([]const u8){ | 94 | const params = [_]clap.Param([]const u8){ |
| @@ -146,11 +138,9 @@ const std = @import("std"); | |||
| 146 | const clap = @import("clap"); | 138 | const clap = @import("clap"); |
| 147 | 139 | ||
| 148 | pub fn main() !void { | 140 | pub fn main() !void { |
| 149 | const params = [_]clap.Param(void){ | 141 | const params = [_]clap.Param(void){clap.Param(void){ |
| 150 | clap.Param(void){ | 142 | .names = clap.Names{ .short = 'h', .long = "help" }, |
| 151 | .names = clap.Names{ .short = 'h', .long = "help" } | 143 | }}; |
| 152 | }, | ||
| 153 | }; | ||
| 154 | 144 | ||
| 155 | var direct_allocator = std.heap.DirectAllocator.init(); | 145 | var direct_allocator = std.heap.DirectAllocator.init(); |
| 156 | const allocator = &direct_allocator.allocator; | 146 | const allocator = &direct_allocator.allocator; |
| @@ -204,11 +194,11 @@ pub fn main() !void { | |||
| 204 | [_]clap.Param([]const u8){ | 194 | [_]clap.Param([]const u8){ |
| 205 | clap.Param([]const u8){ | 195 | clap.Param([]const u8){ |
| 206 | .id = "Display this help and exit.", | 196 | .id = "Display this help and exit.", |
| 207 | .names = clap.Names{ .short = 'h', .long = "help" } | 197 | .names = clap.Names{ .short = 'h', .long = "help" }, |
| 208 | }, | 198 | }, |
| 209 | clap.Param([]const u8){ | 199 | clap.Param([]const u8){ |
| 210 | .id = "Output version information and exit.", | 200 | .id = "Output version information and exit.", |
| 211 | .names = clap.Names{ .short = 'v', .long = "version" } | 201 | .names = clap.Names{ .short = 'v', .long = "version" }, |
| 212 | }, | 202 | }, |
| 213 | }, | 203 | }, |
| 214 | ); | 204 | ); |
diff --git a/example/comptime-clap.zig b/example/comptime-clap.zig index 695fa62..0b6d2c4 100644 --- a/example/comptime-clap.zig +++ b/example/comptime-clap.zig | |||
| @@ -4,13 +4,7 @@ const clap = @import("clap"); | |||
| 4 | const debug = std.debug; | 4 | const debug = std.debug; |
| 5 | 5 | ||
| 6 | pub fn main() !void { | 6 | pub fn main() !void { |
| 7 | const stdout_file = try std.io.getStdOut(); | 7 | const allocator = std.heap.direct_allocator; |
| 8 | var stdout_out_stream = stdout_file.outStream(); | ||
| 9 | const stdout = &stdout_out_stream.stream; | ||
| 10 | |||
| 11 | var direct_allocator = std.heap.DirectAllocator.init(); | ||
| 12 | const allocator = &direct_allocator.allocator; | ||
| 13 | defer direct_allocator.deinit(); | ||
| 14 | 8 | ||
| 15 | // First we specify what parameters our program can take. | 9 | // First we specify what parameters our program can take. |
| 16 | const params = [_]clap.Param([]const u8){ | 10 | const params = [_]clap.Param([]const u8){ |
diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig index 71a2fca..d15e5b7 100644 --- a/example/streaming-clap.zig +++ b/example/streaming-clap.zig | |||
| @@ -4,9 +4,7 @@ const clap = @import("clap"); | |||
| 4 | const debug = std.debug; | 4 | const debug = std.debug; |
| 5 | 5 | ||
| 6 | pub fn main() !void { | 6 | pub fn main() !void { |
| 7 | var direct_allocator = std.heap.DirectAllocator.init(); | 7 | const allocator = std.heap.direct_allocator; |
| 8 | const allocator = &direct_allocator.allocator; | ||
| 9 | defer direct_allocator.deinit(); | ||
| 10 | 8 | ||
| 11 | // First we specify what parameters our program can take. | 9 | // First we specify what parameters our program can take. |
| 12 | const params = [_]clap.Param(u8){ | 10 | const params = [_]clap.Param(u8){ |
diff --git a/src/comptime.zig b/src/comptime.zig index d872b82..3220ad6 100644 --- a/src/comptime.zig +++ b/src/comptime.zig | |||
| @@ -11,19 +11,12 @@ pub fn ComptimeClap(comptime Id: type, comptime params: []const clap.Param(Id)) | |||
| 11 | var options: usize = 0; | 11 | var options: usize = 0; |
| 12 | var converted_params: []const clap.Param(usize) = [_]clap.Param(usize){}; | 12 | var converted_params: []const clap.Param(usize) = [_]clap.Param(usize){}; |
| 13 | for (params) |param| { | 13 | for (params) |param| { |
| 14 | const index = blk: { | 14 | var index: usize = 0; |
| 15 | if (param.names.long == null and param.names.short == null) | 15 | if (param.names.long != null or param.names.short != null) { |
| 16 | break :blk 0; | 16 | const ptr = if (param.takes_value) &options else &flags; |
| 17 | if (param.takes_value) { | 17 | index = ptr.*; |
| 18 | const res = options; | 18 | ptr.* += 1; |
| 19 | options += 1; | 19 | } |
| 20 | break :blk res; | ||
| 21 | } | ||
| 22 | |||
| 23 | const res = flags; | ||
| 24 | flags += 1; | ||
| 25 | break :blk res; | ||
| 26 | }; | ||
| 27 | 20 | ||
| 28 | const converted = clap.Param(usize){ | 21 | const converted = clap.Param(usize){ |
| 29 | .id = index, | 22 | .id = index, |