command: remove init function

Maybe this is short-sighted, but it wasn't really doing anything. Chuck
it.
This commit is contained in:
torque 2023-04-04 23:22:12 -07:00
parent e09d542c3a
commit 910cdd8106
Signed by: torque
SSH Key Fingerprint: SHA256:nCrXefBNo6EbjNSQhv0nXmEg/VuNq3sMF5b8zETw3Tk
2 changed files with 13 additions and 11 deletions

View File

@ -6,11 +6,13 @@ const CommandBuilder = noclip.CommandBuilder;
const Choice = enum { first, second };
const cli = cmd: {
var cmd = CommandBuilder(u32).init(
var cmd = CommandBuilder(u32){
.description =
\\The definitive noclip demonstration utility
\\
\\This command demonstrates the functionality of the noclip library. cool!
);
,
};
cmd.add_option(.{ .OutputType = struct { u8, u8 } }, .{
.name = "test",
.short_tag = "-t",
@ -69,11 +71,13 @@ const cli = cmd: {
};
const subcommand = cmd: {
var cmd = CommandBuilder(void).init(
var cmd = CommandBuilder(void){
.description =
\\Perform some sort of work
\\
\\This subcommand is a mystery. It probably does something, but nobody is sure what.
);
,
};
cmd.add_flag(.{}, .{
.name = "flag",
.truthy = .{ .short_tag = "-f", .long_tag = "--flag" },
@ -95,7 +99,7 @@ fn cli_handler(context: *u32, result: cli.Output()) !void {
std.debug.print("callback is working {d}\n", .{result.default});
}
pub fn main() !void {
pub fn main() !u8 {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = arena.allocator();
@ -107,5 +111,7 @@ pub fn main() !void {
try parser.add_subcommand("verb", subcon.interface());
const iface = parser.interface(&context);
try iface.execute();
iface.execute() catch return 1;
return 0;
}

View File

@ -77,16 +77,12 @@ pub fn CommandBuilder(comptime UserContext: type) type {
param_spec: ncmeta.TupleBuilder = .{},
// this is a strange hack, but it's easily the path of least resistance
help_flag: ShortLongPair = .{ .short_tag = "-h", .long_tag = "--help" },
description: []const u8,
/// if any subcommands are provided, one of them must be specified, or the command has failed.
subcommand_required: bool = true,
description: []const u8,
pub const UserContextType = UserContext;
pub fn init(comptime description: []const u8) @This() {
return .{ .description = description };
}
pub fn create_parser(
comptime self: @This(),
comptime callback: self.CallbackSignature(),