diff --git a/demo/demo.zig b/demo/demo.zig index 7e5d73e..ece8355 100644 --- a/demo/demo.zig +++ b/demo/demo.zig @@ -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; } diff --git a/source/command.zig b/source/command.zig index 359ff2d..a963f13 100644 --- a/source/command.zig +++ b/source/command.zig @@ -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(),