2022-11-27 01:31:20 -08:00
|
|
|
const meta = @import("./meta.zig");
|
|
|
|
const params = @import("./params.zig");
|
|
|
|
const noclip = @import("./noclip.zig");
|
|
|
|
|
|
|
|
fn GenCommand(comptime UserContext: type, comptime cData: params.CommandData) type {
|
|
|
|
return struct {
|
|
|
|
argspec: meta.MutableTuple = .{},
|
|
|
|
|
sorta help text generation
This mostly works. Subcommands are utterly broken because we blindly
consume an additional argument to get the program name, which we
should not do.
This code was always kind of spaghetti, but it's getting worse. I want
to refactor it into something that doesn't make me cringe, but at the
same time, this project was intended to be a means to an end rather
than the end itself, and it kind of feels a bit silly to spend a ton
of time on it. On the other hand, relying on it for other projects
seems silly if it's a fragile mess. The goal was to get it into a
usable state and then hack on it as necessary, but it still has a ways
to go to get there, and working on it is kind of painful, in an
existential fashion.
Perhaps I will attempt to rewrite it, get halfway, and stall forever.
Thanks for reading my cool commit message blog. Bye.
2023-03-20 23:13:58 -07:00
|
|
|
StringOption: type = params.StringOption(UserContext),
|
|
|
|
StringArgument: type = params.StringArg(UserContext),
|
2022-11-27 01:31:20 -08:00
|
|
|
Flag: type = params.Flag(UserContext),
|
sorta help text generation
This mostly works. Subcommands are utterly broken because we blindly
consume an additional argument to get the program name, which we
should not do.
This code was always kind of spaghetti, but it's getting worse. I want
to refactor it into something that doesn't make me cringe, but at the
same time, this project was intended to be a means to an end rather
than the end itself, and it kind of feels a bit silly to spend a ton
of time on it. On the other hand, relying on it for other projects
seems silly if it's a fragile mess. The goal was to get it into a
usable state and then hack on it as necessary, but it still has a ways
to go to get there, and working on it is kind of painful, in an
existential fashion.
Perhaps I will attempt to rewrite it, get halfway, and stall forever.
Thanks for reading my cool commit message blog. Bye.
2023-03-20 23:13:58 -07:00
|
|
|
defaultHelpFlag: params.Flag(UserContext) = HelpFlag(undefined, .{}),
|
2022-11-27 01:31:20 -08:00
|
|
|
|
|
|
|
pub fn Option(comptime _: @This(), comptime Output: type) type {
|
|
|
|
return params.Option(.{ .Output = Output, .UserContext = UserContext });
|
|
|
|
}
|
sorta help text generation
This mostly works. Subcommands are utterly broken because we blindly
consume an additional argument to get the program name, which we
should not do.
This code was always kind of spaghetti, but it's getting worse. I want
to refactor it into something that doesn't make me cringe, but at the
same time, this project was intended to be a means to an end rather
than the end itself, and it kind of feels a bit silly to spend a ton
of time on it. On the other hand, relying on it for other projects
seems silly if it's a fragile mess. The goal was to get it into a
usable state and then hack on it as necessary, but it still has a ways
to go to get there, and working on it is kind of painful, in an
existential fashion.
Perhaps I will attempt to rewrite it, get halfway, and stall forever.
Thanks for reading my cool commit message blog. Bye.
2023-03-20 23:13:58 -07:00
|
|
|
|
2022-11-27 01:31:20 -08:00
|
|
|
pub fn Argument(comptime _: @This(), comptime Output: type) type {
|
|
|
|
return params.Argument(.{ .Output = Output, .UserContext = UserContext });
|
|
|
|
}
|
|
|
|
|
sorta help text generation
This mostly works. Subcommands are utterly broken because we blindly
consume an additional argument to get the program name, which we
should not do.
This code was always kind of spaghetti, but it's getting worse. I want
to refactor it into something that doesn't make me cringe, but at the
same time, this project was intended to be a means to an end rather
than the end itself, and it kind of feels a bit silly to spend a ton
of time on it. On the other hand, relying on it for other projects
seems silly if it's a fragile mess. The goal was to get it into a
usable state and then hack on it as necessary, but it still has a ways
to go to get there, and working on it is kind of painful, in an
existential fashion.
Perhaps I will attempt to rewrite it, get halfway, and stall forever.
Thanks for reading my cool commit message blog. Bye.
2023-03-20 23:13:58 -07:00
|
|
|
pub fn HelpFlag(comptime _: @This(), comptime args: params.HelpFlagArgs) params.Flag(UserContext) {
|
2022-11-27 01:31:20 -08:00
|
|
|
return params.HelpFlag(UserContext, args);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is really only sort of conditionally useful. It would be nice
|
|
|
|
// to add the Subcommand directly to the argspec, except what we
|
|
|
|
// actually have to have is the subcommand.Parser, and that can't be
|
|
|
|
// created until all of the options are attached to that command. I
|
|
|
|
// believe we could handle it with an `inline for` construct in the
|
|
|
|
// parser executor, but I'm not particularly convinced that those
|
|
|
|
// contortions provide a particularly real benefit. The main change
|
|
|
|
// would be specifying the subcommands after the main command, whereas
|
|
|
|
// in the current state of things, they're generally defined before the
|
|
|
|
// main command.
|
|
|
|
pub fn Subcommand(comptime subData: params.CommandData) GenCommand(UserContext, subData) {
|
|
|
|
return Command(UserContext, subData);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn add(comptime self: *@This(), comptime parameter: anytype) void {
|
|
|
|
self.argspec.add(parameter);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn commandSpec(comptime self: @This()) self.argspec.TupleType() {
|
|
|
|
return self.argspec.realTuple();
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn CommandResult(comptime self: @This()) type {
|
|
|
|
return noclip.CommandResult(self.commandSpec(), UserContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn Parser(
|
|
|
|
comptime self: @This(),
|
|
|
|
comptime callback: *const fn (UserContext, noclip.CommandResult(self.commandSpec(), UserContext)) anyerror!void,
|
|
|
|
) noclip.CommandParser(cData, self.commandSpec(), UserContext, callback) {
|
|
|
|
return noclip.CommandParser(cData, self.commandSpec(), UserContext, callback){};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn Command(comptime UserContext: type, comptime cData: params.CommandData) GenCommand(UserContext, cData) {
|
|
|
|
return GenCommand(UserContext, cData){};
|
|
|
|
}
|