const clap = @import("clap"); const std = @import("std"); const debug = std.debug; const io = std.io; const process = std.process; pub fn main() !void { // 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. \\... \\ ); // Declare our own parsers which are used to map the argument strings to other // types. const parsers = comptime .{ .STR = clap.parsers.string, .FILE = clap.parsers.string, .INT = clap.parsers.int(usize, 10), }; var diag = clap.Diagnostic{}; var res = clap.parse(clap.Help, ¶ms, parsers, .{ .diagnostic = &diag, }) catch |err| { diag.report(io.getStdErr().writer(), err) catch {}; return err; }; defer res.deinit(); if (res.args.help) debug.print("--help\n", .{}); if (res.args.number) |n| debug.print("--number = {}\n", .{n}); for (res.args.string) |s| debug.print("--string = {s}\n", .{s}); for (res.positionals) |pos| debug.print("{s}\n", .{pos}); }