command: remove init function
Maybe this is short-sighted, but it wasn't really doing anything. Chuck it.
This commit is contained in:
parent
e09d542c3a
commit
910cdd8106
@ -6,11 +6,13 @@ const CommandBuilder = noclip.CommandBuilder;
|
|||||||
const Choice = enum { first, second };
|
const Choice = enum { first, second };
|
||||||
|
|
||||||
const cli = cmd: {
|
const cli = cmd: {
|
||||||
var cmd = CommandBuilder(u32).init(
|
var cmd = CommandBuilder(u32){
|
||||||
|
.description =
|
||||||
\\The definitive noclip demonstration utility
|
\\The definitive noclip demonstration utility
|
||||||
\\
|
\\
|
||||||
\\This command demonstrates the functionality of the noclip library. cool!
|
\\This command demonstrates the functionality of the noclip library. cool!
|
||||||
);
|
,
|
||||||
|
};
|
||||||
cmd.add_option(.{ .OutputType = struct { u8, u8 } }, .{
|
cmd.add_option(.{ .OutputType = struct { u8, u8 } }, .{
|
||||||
.name = "test",
|
.name = "test",
|
||||||
.short_tag = "-t",
|
.short_tag = "-t",
|
||||||
@ -69,11 +71,13 @@ const cli = cmd: {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const subcommand = cmd: {
|
const subcommand = cmd: {
|
||||||
var cmd = CommandBuilder(void).init(
|
var cmd = CommandBuilder(void){
|
||||||
|
.description =
|
||||||
\\Perform some sort of work
|
\\Perform some sort of work
|
||||||
\\
|
\\
|
||||||
\\This subcommand is a mystery. It probably does something, but nobody is sure what.
|
\\This subcommand is a mystery. It probably does something, but nobody is sure what.
|
||||||
);
|
,
|
||||||
|
};
|
||||||
cmd.add_flag(.{}, .{
|
cmd.add_flag(.{}, .{
|
||||||
.name = "flag",
|
.name = "flag",
|
||||||
.truthy = .{ .short_tag = "-f", .long_tag = "--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});
|
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);
|
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
|
||||||
defer arena.deinit();
|
defer arena.deinit();
|
||||||
const allocator = arena.allocator();
|
const allocator = arena.allocator();
|
||||||
@ -107,5 +111,7 @@ pub fn main() !void {
|
|||||||
try parser.add_subcommand("verb", subcon.interface());
|
try parser.add_subcommand("verb", subcon.interface());
|
||||||
|
|
||||||
const iface = parser.interface(&context);
|
const iface = parser.interface(&context);
|
||||||
try iface.execute();
|
iface.execute() catch return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -77,16 +77,12 @@ pub fn CommandBuilder(comptime UserContext: type) type {
|
|||||||
param_spec: ncmeta.TupleBuilder = .{},
|
param_spec: ncmeta.TupleBuilder = .{},
|
||||||
// this is a strange hack, but it's easily the path of least resistance
|
// this is a strange hack, but it's easily the path of least resistance
|
||||||
help_flag: ShortLongPair = .{ .short_tag = "-h", .long_tag = "--help" },
|
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.
|
/// if any subcommands are provided, one of them must be specified, or the command has failed.
|
||||||
subcommand_required: bool = true,
|
subcommand_required: bool = true,
|
||||||
|
description: []const u8,
|
||||||
|
|
||||||
pub const UserContextType = UserContext;
|
pub const UserContextType = UserContext;
|
||||||
|
|
||||||
pub fn init(comptime description: []const u8) @This() {
|
|
||||||
return .{ .description = description };
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create_parser(
|
pub fn create_parser(
|
||||||
comptime self: @This(),
|
comptime self: @This(),
|
||||||
comptime callback: self.CallbackSignature(),
|
comptime callback: self.CallbackSignature(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user