summaryrefslogtreecommitdiff
path: root/example/simple.zig
diff options
context:
space:
mode:
Diffstat (limited to 'example/simple.zig')
-rw-r--r--example/simple.zig26
1 files changed, 26 insertions, 0 deletions
diff --git a/example/simple.zig b/example/simple.zig
new file mode 100644
index 0000000..f791447
--- /dev/null
+++ b/example/simple.zig
@@ -0,0 +1,26 @@
1const std = @import("std");
2const clap = @import("clap");
3
4const debug = std.debug;
5
6pub fn main() !void {
7 // First we specify what parameters our program can take.
8 // We can use `parseParam` to parse a string to a `Param(Help)`
9 const params = comptime [_]clap.Param(clap.Help){
10 clap.parseParam("-h, --help Display this help and exit. ") catch unreachable,
11 clap.parseParam("-n, --number <NUM> An option parameter, which takes a value.") catch unreachable,
12 clap.Param(clap.Help){
13 .takes_value = true,
14 },
15 };
16
17 var args = try clap.parse(clap.Help, params, std.heap.direct_allocator);
18 defer args.deinit();
19
20 if (args.flag("--help"))
21 debug.warn("--help\n");
22 if (args.option("--number")) |n|
23 debug.warn("--number = {}\n", n);
24 for (args.positionals()) |pos|
25 debug.warn("{}\n", pos);
26}