summaryrefslogtreecommitdiff
path: root/example/usage.zig
diff options
context:
space:
mode:
Diffstat (limited to 'example/usage.zig')
-rw-r--r--example/usage.zig19
1 files changed, 11 insertions, 8 deletions
diff --git a/example/usage.zig b/example/usage.zig
index 90fa310..368a6b3 100644
--- a/example/usage.zig
+++ b/example/usage.zig
@@ -2,15 +2,18 @@ const clap = @import("clap");
2const std = @import("std"); 2const std = @import("std");
3 3
4pub fn main() !void { 4pub fn main() !void {
5 const params = comptime [_]clap.Param(clap.Help){
6 clap.parseParam("-h, --help Display this help and exit. ") catch unreachable,
7 clap.parseParam("-v, --version Output version information and exit. ") catch unreachable,
8 clap.parseParam(" --value <N> An option parameter, which takes a value.") catch unreachable,
9 };
10
11 var args = try clap.parse(clap.Help, &params, .{});
12 defer args.deinit();
13
5 // clap.usage is a function that can print a simple usage message, given a 14 // clap.usage is a function that can print a simple usage message, given a
6 // slice of Param(Help). There is also a usageEx, which can print a 15 // slice of Param(Help). There is also a usageEx, which can print a
7 // usage message for any Param, but it is more verbose to call. 16 // usage message for any Param, but it is more verbose to call.
8 try clap.usage( 17 if (args.flag("--help"))
9 std.io.getStdErr().writer(), 18 return clap.usage(std.io.getStdErr().writer(), &params);
10 comptime &.{
11 clap.parseParam("-h, --help Display this help and exit. ") catch unreachable,
12 clap.parseParam("-v, --version Output version information and exit. ") catch unreachable,
13 clap.parseParam(" --value <N> An option parameter, which takes a value.") catch unreachable,
14 },
15 );
16} 19}