Compare commits
2 Commits
419d8994ba
...
35915191fb
Author | SHA1 | Date | |
---|---|---|---|
35915191fb | |||
76e8dedf14 |
@ -113,17 +113,16 @@ pub fn main() !u8 {
|
|||||||
defer _ = gpa.deinit();
|
defer _ = gpa.deinit();
|
||||||
const allocator = gpa.allocator();
|
const allocator = gpa.allocator();
|
||||||
|
|
||||||
var parser = try cli.createParser(cliHandler, allocator);
|
const base = try noclip.commandGroup(allocator, .{ .description = "base group" });
|
||||||
defer parser.deinitTree();
|
defer base.deinitTree();
|
||||||
|
|
||||||
var context: u32 = 2;
|
var context: u32 = 2;
|
||||||
const sc: []const u8 = "whassup";
|
const sc: []const u8 = "whassup";
|
||||||
|
|
||||||
var subcon = try subcommand.createParser(subHandler, allocator);
|
try base.addSubcommand("main", try cli.createInterface(allocator, cliHandler, &context));
|
||||||
try parser.addSubcommand("verb", subcon.interface(&sc));
|
try base.addSubcommand("other", try subcommand.createInterface(allocator, subHandler, &sc));
|
||||||
|
|
||||||
const iface = parser.interface(&context);
|
try base.execute();
|
||||||
iface.execute() catch return 1;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,21 @@ fn BuilderGenerics(comptime UserContext: type) type {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const GroupOptions = struct {
|
||||||
|
help_flag: ShortLongPair = .{ .short_tag = "-h", .long_tag = "--help" },
|
||||||
|
description: []const u8,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn commandGroup(allocator: std.mem.Allocator, comptime options: GroupOptions) !ParserInterface {
|
||||||
|
const cmd = comptime CommandBuilder(void){
|
||||||
|
.help_flag = options.help_flag,
|
||||||
|
.description = options.description,
|
||||||
|
.subcommand_required = true,
|
||||||
|
};
|
||||||
|
|
||||||
|
return try cmd.createInterface(allocator, cmd.noopCallback());
|
||||||
|
}
|
||||||
|
|
||||||
fn InterfaceCreator(comptime Command: type) type {
|
fn InterfaceCreator(comptime Command: type) type {
|
||||||
return if (Command.ICC.InputType()) |Type|
|
return if (Command.ICC.InputType()) |Type|
|
||||||
struct {
|
struct {
|
||||||
@ -329,6 +344,12 @@ pub fn CommandBuilder(comptime UserContext: type) type {
|
|||||||
return self.param_spec.realTuple();
|
return self.param_spec.realTuple();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn noopCallback(comptime self: @This()) self.CallbackSignature() {
|
||||||
|
return struct {
|
||||||
|
fn callback(_: UserContextType, _: self.Output()) !void {}
|
||||||
|
}.callback;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn CallbackSignature(comptime self: @This()) type {
|
pub fn CallbackSignature(comptime self: @This()) type {
|
||||||
return *const fn (UserContextType, self.Output()) anyerror!void;
|
return *const fn (UserContextType, self.Output()) anyerror!void;
|
||||||
}
|
}
|
||||||
|
@ -7,4 +7,5 @@ pub const parameters = @import("./parameters.zig");
|
|||||||
pub const parser = @import("./parser.zig");
|
pub const parser = @import("./parser.zig");
|
||||||
|
|
||||||
pub const CommandBuilder = command.CommandBuilder;
|
pub const CommandBuilder = command.CommandBuilder;
|
||||||
|
pub const commandGroup = command.commandGroup;
|
||||||
pub const ParserInterface = parser.ParserInterface;
|
pub const ParserInterface = parser.ParserInterface;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user