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:
torque 2023-03-31 15:37:52 -07:00
parent 3acc412f2e
commit 7c9273605d
Signed by: torque
SSH Key Fingerprint: SHA256:nCrXefBNo6EbjNSQhv0nXmEg/VuNq3sMF5b8zETw3Tk

View File

@ -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);