pub fn main() !void { var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer _ = gpa.deinit(); // First we specify what parameters our program can take. // We can use `parseParamsComptime` to parse a string into an array of `Param(Help)`. const params = comptime clap.parseParamsComptime( \\-h, --help Display this help and exit. \\-n, --number An option parameter, which takes a value. \\-s, --string ... An option parameter which can be specified multiple times. \\... \\ ); // Initialize our diagnostics, which can be used for reporting useful errors. // This is optional. You can also pass `.{}` to `clap.parse` if you don't // care about the extra information `Diagnostics` provides. var diag = clap.Diagnostic{}; var res = clap.parse(clap.Help, ¶ms, clap.parsers.default, .{ .diagnostic = &diag, .allocator = gpa.allocator(), }) catch |err| { // Report useful error and exit. try diag.reportToFile(.stderr(), err); return err; }; defer res.deinit(); if (res.args.help != 0) std.debug.print("--help\n", .{}); if (res.args.number) |n| std.debug.print("--number = {}\n", .{n}); for (res.args.string) |s| std.debug.print("--string = {s}\n", .{s}); for (res.positionals[0]) |pos| std.debug.print("{s}\n", .{pos}); } const clap = @import("clap"); const std = @import("std");