aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/deps/zig-clap/clap.zig6
-rw-r--r--src/deps/zig-clap/clap/comptime.zig10
-rw-r--r--src/deps/zig-clap/clap/streaming.zig18
3 files changed, 22 insertions, 12 deletions
diff --git a/src/deps/zig-clap/clap.zig b/src/deps/zig-clap/clap.zig
index 582790c24..65921d9d0 100644
--- a/src/deps/zig-clap/clap.zig
+++ b/src/deps/zig-clap/clap.zig
@@ -29,6 +29,7 @@ pub const Values = enum {
none,
one,
many,
+ one_optional,
};
/// Represents a parameter for the command line.
@@ -109,9 +110,10 @@ fn parseParamRest(line: []const u8) Param(Help) {
if (mem.startsWith(u8, line, "<")) blk: {
const len = mem.indexOfScalar(u8, line, '>') orelse break :blk;
const takes_many = mem.startsWith(u8, line[len + 1 ..], "...");
+ const takes_one_optional = mem.startsWith(u8, line[len + 1 ..], "?");
const help_start = len + 1 + @as(usize, 3) * @boolToInt(takes_many);
return .{
- .takes_value = if (takes_many) .many else .one,
+ .takes_value = if (takes_many) Values.many else if (takes_one_optional) Values.one_optional else Values.one,
.id = .{
.msg = mem.trim(u8, line[help_start..], " \t"),
.value = line[1..len],
@@ -372,6 +374,7 @@ fn printParam(
switch (param.takes_value) {
.none => {},
.one => try stream.print(" <{s}>", .{valueText(context, param)}),
+ .one_optional => try stream.print(" <{s}>?", .{valueText(context, param)}),
.many => try stream.print(" <{s}>...", .{valueText(context, param)}),
}
}
@@ -477,6 +480,7 @@ pub fn usageFull(
switch (param.takes_value) {
.none => {},
.one => try cs.print(" <{s}>", .{try valueText(context, param)}),
+ .one_optional => try cs.print(" <{s}>?", .{try valueText(context, param)}),
.many => try cs.print(" <{s}>...", .{try valueText(context, param)}),
}
diff --git a/src/deps/zig-clap/clap/comptime.zig b/src/deps/zig-clap/clap/comptime.zig
index 009d2b95d..f55be3f1a 100644
--- a/src/deps/zig-clap/clap/comptime.zig
+++ b/src/deps/zig-clap/clap/comptime.zig
@@ -20,7 +20,7 @@ pub fn ComptimeClap(
if (param.names.long != null or param.names.short != null) {
const ptr = switch (param.takes_value) {
.none => &_flags,
- .one => &_single_options,
+ .one_optional, .one => &_single_options,
.many => &_multi_options,
};
index = ptr.*;
@@ -71,10 +71,10 @@ pub fn ComptimeClap(
const param = arg.param;
if (param.names.long == null and param.names.short == null) {
try pos.append(arg.value.?);
- } else if (param.takes_value == .one) {
+ } else if (param.takes_value == .one or param.takes_value == .one_optional) {
debug.assert(res.single_options.len != 0);
if (res.single_options.len != 0)
- res.single_options[param.id] = arg.value.?;
+ res.single_options[param.id] = arg.value orelse "";
} else if (param.takes_value == .many) {
debug.assert(multis.len != 0);
if (multis.len != 0)
@@ -101,7 +101,7 @@ pub fn ComptimeClap(
pub fn flag(parser: @This(), comptime name: []const u8) bool {
const param = comptime findParam(name);
- if (param.takes_value != .none)
+ if (param.takes_value != .none and param.takes_value != .one_optional)
@compileError(name ++ " is an option and not a flag.");
return parser.flags[param.id];
@@ -120,7 +120,7 @@ pub fn ComptimeClap(
const param = comptime findParam(name);
if (param.takes_value == .none)
@compileError(name ++ " is a flag and not an option.");
- if (param.takes_value == .one)
+ if (param.takes_value == .one or param.takes_value == .one_optional)
@compileError(name ++ " takes one option, not multiple.");
return parser.multi_options[param.id];
diff --git a/src/deps/zig-clap/clap/streaming.zig b/src/deps/zig-clap/clap/streaming.zig
index e7991cb53..702e9e6d5 100644
--- a/src/deps/zig-clap/clap/streaming.zig
+++ b/src/deps/zig-clap/clap/streaming.zig
@@ -56,8 +56,10 @@ pub fn StreamingClap(comptime Id: type, comptime ArgIterator: type) type {
}
fn normal(parser: *@This()) !?Arg(Id) {
+ const ArgType = Arg(Id);
const arg_info = (try parser.parseNextArg()) orelse return null;
const arg = arg_info.arg;
+
switch (arg_info.kind) {
.long => {
const eql_index = mem.indexOfScalar(u8, arg, '=');
@@ -73,18 +75,22 @@ pub fn StreamingClap(comptime Id: type, comptime ArgIterator: type) type {
if (maybe_value != null)
return parser.err(arg, .{ .long = name }, error.DoesntTakeValue);
- return Arg(Id){ .param = param };
+ return ArgType{ .param = param };
}
const value = blk: {
if (maybe_value) |v|
break :blk v;
- break :blk (try parser.iter.next()) orelse
- return parser.err(arg, .{ .long = name }, error.MissingValue);
+ break :blk (try parser.iter.next()) orelse brk2: {
+ if (param.takes_value != .one_optional)
+ return parser.err(arg, .{ .long = name }, error.MissingValue);
+
+ break :brk2 "";
+ };
};
- return Arg(Id){ .param = param, .value = value };
+ return ArgType{ .param = param, .value = value };
}
return null;
@@ -135,8 +141,8 @@ pub fn StreamingClap(comptime Id: type, comptime ArgIterator: type) type {
}
const next_is_eql = if (next_index < arg.len) arg[next_index] == '=' else false;
- if (param.takes_value == .none) {
- if (next_is_eql)
+ if (param.takes_value == .none or param.takes_value == .one_optional) {
+ if (next_is_eql and param.takes_value == .none)
return parser.err(arg, .{ .short = short }, error.DoesntTakeValue);
return Arg(Id){ .param = param };
}