diff --git a/src/Value.zig b/src/Value.zig index ca70db0..32b8a0b 100644 --- a/src/Value.zig +++ b/src/Value.zig @@ -109,7 +109,7 @@ pub fn Typed(comptime SetT: type, comptime config: Config) type { /// Parse the given argument token (`arg`) to this Value's Type. pub fn parse(self: *const @This(), arg: []const u8) !ChildT { - if (self.parse_fn != null) return self.parse_fn.?(arg) catch error.CannotParseArgToValue; + if (self.parse_fn) |parseFn| return parseFn(arg) catch error.CannotParseArgToValue; var san_arg_buf: [512]u8 = undefined; var san_arg = toLower(san_arg_buf[0..], arg); return switch (@typeInfo(ChildT)) { @@ -146,7 +146,7 @@ pub fn Typed(comptime SetT: type, comptime config: Config) type { // Single Arg const parsed_arg = try self.parse(set_arg); @constCast(self).is_set = - if (self.valid_fn != null) self.valid_fn.?(parsed_arg) + if (self.valid_fn) |validFn| validFn(parsed_arg) else true; if (self.is_set) { switch (self.set_behavior) { diff --git a/src/cova.zig b/src/cova.zig index da965ed..a8d1826 100644 --- a/src/cova.zig +++ b/src/cova.zig @@ -127,6 +127,8 @@ pub const ParseConfig = struct { auto_handle_usage_help: bool = true, /// Decide how to react to parsing errors. err_reaction: ParseErrorReaction = .Help, + /// Enable Option Termination using `--` per the POSIX standard (or whatever symbol is chosen for Option long names). + enable_opt_termination: bool = true, /// Reactions for Parsing Errors. const ParseErrorReaction = enum { @@ -152,6 +154,7 @@ pub fn parseArgs( if (!cmd._is_init) return error.CommandNotInitialized; var val_idx: u8 = 0; + var opt_term: bool = false; const OptionT = CommandT.OptionT; // Bypass argument 0 (the filename being executed); @@ -181,7 +184,7 @@ pub fn parseArgs( log.debug("No Commands Matched for Command '{s}'.", .{ cmd.name }); } // ...Then for any Options... - if (cmd.opts != null) { + if (cmd.opts != null and !opt_term) { log.debug("Attempting to Parse Options...", .{}); const short_pf = OptionT.short_prefix; const long_pf = OptionT.long_prefix; @@ -263,6 +266,10 @@ pub fn parseArgs( } // - Long Options else if (mem.eql(u8, arg[0..long_pf.len], long_pf)) { + if (arg.len == long_pf.len) { + opt_term = true; + continue; + } const split_idx = (mem.indexOfAny(u8, arg[long_pf.len..], OptionT.opt_val_seps) orelse arg.len - long_pf.len) + long_pf.len; const long_opt = arg[long_pf.len..split_idx]; const sep_arg = if (split_idx < arg.len) arg[split_idx + 1..] else "";