diff options
| author | 2021-05-08 18:08:52 +0200 | |
|---|---|---|
| committer | 2021-05-08 18:08:52 +0200 | |
| commit | 4c14bfd5188bb61d7076bc33fccbcc6a5e9dac01 (patch) | |
| tree | 8f5267e4da9bbc14bd595697797457911d4b3081 /clap/comptime.zig | |
| parent | Refactor Diagnostic (and others) into a ParseOption struct (diff) | |
| download | zig-clap-4c14bfd5188bb61d7076bc33fccbcc6a5e9dac01.tar.gz zig-clap-4c14bfd5188bb61d7076bc33fccbcc6a5e9dac01.tar.xz zig-clap-4c14bfd5188bb61d7076bc33fccbcc6a5e9dac01.zip | |
Modernize codebase
* Better naming for variables
* Follow naming style of enums
* Use `writer()` instead of `outStream()`
* Change many initializers to be a one liner
* Don't explicitly initialize fields to their default value
Diffstat (limited to 'clap/comptime.zig')
| -rw-r--r-- | clap/comptime.zig | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/clap/comptime.zig b/clap/comptime.zig index 9bec38e..122ff16 100644 --- a/clap/comptime.zig +++ b/clap/comptime.zig | |||
| @@ -19,9 +19,9 @@ pub fn ComptimeClap( | |||
| 19 | var index: usize = 0; | 19 | var index: usize = 0; |
| 20 | if (param.names.long != null or param.names.short != null) { | 20 | if (param.names.long != null or param.names.short != null) { |
| 21 | const ptr = switch (param.takes_value) { | 21 | const ptr = switch (param.takes_value) { |
| 22 | .None => &flags, | 22 | .none => &flags, |
| 23 | .One => &single_options, | 23 | .one => &single_options, |
| 24 | .Many => &multi_options, | 24 | .many => &multi_options, |
| 25 | }; | 25 | }; |
| 26 | index = ptr.*; | 26 | index = ptr.*; |
| 27 | ptr.* += 1; | 27 | ptr.* += 1; |
| @@ -67,11 +67,11 @@ pub fn ComptimeClap( | |||
| 67 | const param = arg.param; | 67 | const param = arg.param; |
| 68 | if (param.names.long == null and param.names.short == null) { | 68 | if (param.names.long == null and param.names.short == null) { |
| 69 | try pos.append(arg.value.?); | 69 | try pos.append(arg.value.?); |
| 70 | } else if (param.takes_value == .One) { | 70 | } else if (param.takes_value == .one) { |
| 71 | debug.assert(res.single_options.len != 0); | 71 | debug.assert(res.single_options.len != 0); |
| 72 | if (res.single_options.len != 0) | 72 | if (res.single_options.len != 0) |
| 73 | res.single_options[param.id] = arg.value.?; | 73 | res.single_options[param.id] = arg.value.?; |
| 74 | } else if (param.takes_value == .Many) { | 74 | } else if (param.takes_value == .many) { |
| 75 | debug.assert(multis.len != 0); | 75 | debug.assert(multis.len != 0); |
| 76 | if (multis.len != 0) | 76 | if (multis.len != 0) |
| 77 | try multis[param.id].append(arg.value.?); | 77 | try multis[param.id].append(arg.value.?); |
| @@ -97,7 +97,7 @@ pub fn ComptimeClap( | |||
| 97 | 97 | ||
| 98 | pub fn flag(parser: @This(), comptime name: []const u8) bool { | 98 | pub fn flag(parser: @This(), comptime name: []const u8) bool { |
| 99 | const param = comptime findParam(name); | 99 | const param = comptime findParam(name); |
| 100 | if (param.takes_value != .None) | 100 | if (param.takes_value != .none) |
| 101 | @compileError(name ++ " is an option and not a flag."); | 101 | @compileError(name ++ " is an option and not a flag."); |
| 102 | 102 | ||
| 103 | return parser.flags[param.id]; | 103 | return parser.flags[param.id]; |
| @@ -105,18 +105,18 @@ pub fn ComptimeClap( | |||
| 105 | 105 | ||
| 106 | pub fn option(parser: @This(), comptime name: []const u8) ?[]const u8 { | 106 | pub fn option(parser: @This(), comptime name: []const u8) ?[]const u8 { |
| 107 | const param = comptime findParam(name); | 107 | const param = comptime findParam(name); |
| 108 | if (param.takes_value == .None) | 108 | if (param.takes_value == .none) |
| 109 | @compileError(name ++ " is a flag and not an option."); | 109 | @compileError(name ++ " is a flag and not an option."); |
| 110 | if (param.takes_value == .Many) | 110 | if (param.takes_value == .many) |
| 111 | @compileError(name ++ " takes many options, not one."); | 111 | @compileError(name ++ " takes many options, not one."); |
| 112 | return parser.single_options[param.id]; | 112 | return parser.single_options[param.id]; |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | pub fn options(parser: @This(), comptime name: []const u8) []const []const u8 { | 115 | pub fn options(parser: @This(), comptime name: []const u8) []const []const u8 { |
| 116 | const param = comptime findParam(name); | 116 | const param = comptime findParam(name); |
| 117 | if (param.takes_value == .None) | 117 | if (param.takes_value == .none) |
| 118 | @compileError(name ++ " is a flag and not an option."); | 118 | @compileError(name ++ " is a flag and not an option."); |
| 119 | if (param.takes_value == .One) | 119 | if (param.takes_value == .one) |
| 120 | @compileError(name ++ " takes one option, not multiple."); | 120 | @compileError(name ++ " takes one option, not multiple."); |
| 121 | 121 | ||
| 122 | return parser.multi_options[param.id]; | 122 | return parser.multi_options[param.id]; |