diff options
| author | 2022-10-03 12:57:05 +0200 | |
|---|---|---|
| committer | 2022-10-03 12:57:05 +0200 | |
| commit | e5d09c4b2d121025ad7195b2de704451e6306807 (patch) | |
| tree | 6310a523cdadabf57df7b06f1d664552f5e6ba7d /clap.zig | |
| parent | Add function for getting the prefix of a param name (diff) | |
| download | zig-clap-e5d09c4b2d121025ad7195b2de704451e6306807.tar.gz zig-clap-e5d09c4b2d121025ad7195b2de704451e6306807.tar.xz zig-clap-e5d09c4b2d121025ad7195b2de704451e6306807.zip | |
Fix regression from last commit
Diffstat (limited to '')
| -rw-r--r-- | clap.zig | 25 |
1 files changed, 14 insertions, 11 deletions
| @@ -36,7 +36,7 @@ pub const Names = struct { | |||
| 36 | return .{ .kind = .short, .name = casted }; | 36 | return .{ .kind = .short, .name = casted }; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | return .{ .kind = .positinal, .name = "" }; | 39 | return .{ .kind = .positional, .name = "" }; |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | pub const Longest = struct { | 42 | pub const Longest = struct { |
| @@ -47,10 +47,10 @@ pub const Names = struct { | |||
| 47 | pub const Kind = enum { | 47 | pub const Kind = enum { |
| 48 | long, | 48 | long, |
| 49 | short, | 49 | short, |
| 50 | positinal, | 50 | positional, |
| 51 | 51 | ||
| 52 | pub fn prefix(l: Longest) []const u8 { | 52 | pub fn prefix(kind: Kind) []const u8 { |
| 53 | return switch (l.kind) { | 53 | return switch (kind) { |
| 54 | .long => "--", | 54 | .long => "--", |
| 55 | .short => "-", | 55 | .short => "-", |
| 56 | .positional => "", | 56 | .positional => "", |
| @@ -564,7 +564,10 @@ pub const Diagnostic = struct { | |||
| 564 | /// Default diagnostics reporter when all you want is English with no colors. | 564 | /// Default diagnostics reporter when all you want is English with no colors. |
| 565 | /// Use this as a reference for implementing your own if needed. | 565 | /// Use this as a reference for implementing your own if needed. |
| 566 | pub fn report(diag: Diagnostic, stream: anytype, err: anyerror) !void { | 566 | pub fn report(diag: Diagnostic, stream: anytype, err: anyerror) !void { |
| 567 | const longest = diag.name.longest(); | 567 | var longest = diag.name.longest(); |
| 568 | if (longest.kind == .positional) | ||
| 569 | longest.name = diag.arg; | ||
| 570 | |||
| 568 | switch (err) { | 571 | switch (err) { |
| 569 | streaming.Error.DoesntTakeValue => try stream.print( | 572 | streaming.Error.DoesntTakeValue => try stream.print( |
| 570 | "The argument '{s}{s}' does not take a value\n", | 573 | "The argument '{s}{s}' does not take a value\n", |
| @@ -807,7 +810,7 @@ fn parseArg( | |||
| 807 | try @field(arguments, longest.name).append(allocator, value); | 810 | try @field(arguments, longest.name).append(allocator, value); |
| 808 | }, | 811 | }, |
| 809 | }, | 812 | }, |
| 810 | .positinal => try positionals.append(try parser(arg.value.?)), | 813 | .positional => try positionals.append(try parser(arg.value.?)), |
| 811 | } | 814 | } |
| 812 | } | 815 | } |
| 813 | 816 | ||
| @@ -841,7 +844,7 @@ fn FindPositionalType( | |||
| 841 | fn findPositional(comptime Id: type, params: []const Param(Id)) ?Param(Id) { | 844 | fn findPositional(comptime Id: type, params: []const Param(Id)) ?Param(Id) { |
| 842 | for (params) |param| { | 845 | for (params) |param| { |
| 843 | const longest = param.names.longest(); | 846 | const longest = param.names.longest(); |
| 844 | if (longest.kind == .positinal) | 847 | if (longest.kind == .positional) |
| 845 | return param; | 848 | return param; |
| 846 | } | 849 | } |
| 847 | 850 | ||
| @@ -872,7 +875,7 @@ fn deinitArgs( | |||
| 872 | ) void { | 875 | ) void { |
| 873 | inline for (params) |param| { | 876 | inline for (params) |param| { |
| 874 | const longest = comptime param.names.longest(); | 877 | const longest = comptime param.names.longest(); |
| 875 | if (longest.kind == .positinal) | 878 | if (longest.kind == .positional) |
| 876 | continue; | 879 | continue; |
| 877 | if (param.takes_value != .many) | 880 | if (param.takes_value != .many) |
| 878 | continue; | 881 | continue; |
| @@ -904,7 +907,7 @@ fn Arguments( | |||
| 904 | var i: usize = 0; | 907 | var i: usize = 0; |
| 905 | for (params) |param| { | 908 | for (params) |param| { |
| 906 | const longest = param.names.longest(); | 909 | const longest = param.names.longest(); |
| 907 | if (longest.kind == .positinal) | 910 | if (longest.kind == .positional) |
| 908 | continue; | 911 | continue; |
| 909 | 912 | ||
| 910 | const T = ParamType(Id, param, value_parsers); | 913 | const T = ParamType(Id, param, value_parsers); |
| @@ -1121,7 +1124,7 @@ pub fn help( | |||
| 1121 | 1124 | ||
| 1122 | var first_paramter: bool = true; | 1125 | var first_paramter: bool = true; |
| 1123 | for (params) |param| { | 1126 | for (params) |param| { |
| 1124 | if (param.names.longest().kind == .positinal) | 1127 | if (param.names.longest().kind == .positional) |
| 1125 | continue; | 1128 | continue; |
| 1126 | if (!first_paramter) | 1129 | if (!first_paramter) |
| 1127 | try writer.writeByteNTimes('\n', opt.spacing_between_parameters); | 1130 | try writer.writeByteNTimes('\n', opt.spacing_between_parameters); |
| @@ -1694,7 +1697,7 @@ test "clap.help" { | |||
| 1694 | /// [-abc] [--longa] [-d <T>] [--longb <T>] <T> | 1697 | /// [-abc] [--longa] [-d <T>] [--longb <T>] <T> |
| 1695 | /// | 1698 | /// |
| 1696 | /// First all none value taking parameters, which have a short name are printed, then non | 1699 | /// First all none value taking parameters, which have a short name are printed, then non |
| 1697 | /// positional parameters and finally the positinal. | 1700 | /// positional parameters and finally the positional. |
| 1698 | pub fn usage(stream: anytype, comptime Id: type, params: []const Param(Id)) !void { | 1701 | pub fn usage(stream: anytype, comptime Id: type, params: []const Param(Id)) !void { |
| 1699 | var cos = io.countingWriter(stream); | 1702 | var cos = io.countingWriter(stream); |
| 1700 | const cs = cos.writer(); | 1703 | const cs = cos.writer(); |