parser: segment eager and normal conversion
The main difference is that regular conversion now only happens after the entire command line (including all subcommands) have been parsed. This means that a failing normal converter won't prevent subcommand eager converters from running. However, parsing errors can still preclude eager converters and subcommand parsing from happening.
This commit is contained in:
parent
3acc412f2e
commit
7c9273605d
@ -117,8 +117,7 @@ pub fn Parser(comptime command: anytype, comptime callback: anytype) type {
|
||||
pub fn subparse(self: *@This(), context: *UserContext, args: [][:0]u8, env: std.process.EnvMap) anyerror!void {
|
||||
const sliceto = try self.parse(args);
|
||||
try self.read_environment(env);
|
||||
// try self.convert_eager(context);
|
||||
try self.convert(context);
|
||||
try self.convert_eager(context);
|
||||
|
||||
inline for (@typeInfo(@TypeOf(self.intermediate)).Struct.fields) |field| {
|
||||
if (@field(self.intermediate, field.name) == null) {
|
||||
@ -133,7 +132,7 @@ pub fn Parser(comptime command: anytype, comptime callback: anytype) type {
|
||||
}
|
||||
|
||||
pub fn finish(self: *@This(), context: *UserContext) anyerror!void {
|
||||
// try self.convert(context);
|
||||
try self.convert(context);
|
||||
try callback(context, self.output);
|
||||
if (self.subcommand) |verb| try verb.finish();
|
||||
}
|
||||
@ -382,13 +381,15 @@ pub fn Parser(comptime command: anytype, comptime callback: anytype) type {
|
||||
}
|
||||
}
|
||||
|
||||
fn convert(self: *@This(), context: *UserContext) NoclipError!void {
|
||||
fn convert_eager(self: *@This(), context: *UserContext) NoclipError!void {
|
||||
inline for (comptime parameters) |param| {
|
||||
if (comptime param.eager) {
|
||||
try self.convert_param(param, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn convert(self: *@This(), context: *UserContext) NoclipError!void {
|
||||
inline for (comptime parameters) |param| {
|
||||
if (comptime !param.eager) {
|
||||
try self.convert_param(param, context);
|
||||
|
Loading…
x
Reference in New Issue
Block a user