summaryrefslogtreecommitdiff
path: root/example/simple.zig
diff options
context:
space:
mode:
authorGravatar Jimmi Holst Christensen2023-12-13 08:53:06 +0100
committerGravatar Jimmi Holst Christensen2023-12-13 08:53:06 +0100
commitfeffdff4094ea3927eb3880b46b65e700f1e86fb (patch)
tree071a86610548ebed5b8bec0617cf79cbeeee65fd /example/simple.zig
parentFix short only params not getting fields in `Arguments` (diff)
downloadzig-clap-no-default-allocator.tar.gz
zig-clap-no-default-allocator.tar.xz
zig-clap-no-default-allocator.zip
Remove the default allocator from `ParseOptions`no-default-allocator
fixes #111
Diffstat (limited to 'example/simple.zig')
-rw-r--r--example/simple.zig4
1 files changed, 4 insertions, 0 deletions
diff --git a/example/simple.zig b/example/simple.zig
index 429f095..a7207c7 100644
--- a/example/simple.zig
+++ b/example/simple.zig
@@ -5,6 +5,9 @@ const debug = std.debug;
5const io = std.io; 5const io = std.io;
6 6
7pub fn main() !void { 7pub fn main() !void {
8 var gpa = std.heap.GeneralPurposeAllocator(.{}){};
9 defer _ = gpa.deinit();
10
8 // First we specify what parameters our program can take. 11 // First we specify what parameters our program can take.
9 // We can use `parseParamsComptime` to parse a string into an array of `Param(Help)` 12 // We can use `parseParamsComptime` to parse a string into an array of `Param(Help)`
10 const params = comptime clap.parseParamsComptime( 13 const params = comptime clap.parseParamsComptime(
@@ -21,6 +24,7 @@ pub fn main() !void {
21 var diag = clap.Diagnostic{}; 24 var diag = clap.Diagnostic{};
22 var res = clap.parse(clap.Help, &params, clap.parsers.default, .{ 25 var res = clap.parse(clap.Help, &params, clap.parsers.default, .{
23 .diagnostic = &diag, 26 .diagnostic = &diag,
27 .allocator = gpa.allocator(),
24 }) catch |err| { 28 }) catch |err| {
25 // Report useful error and exit 29 // Report useful error and exit
26 diag.report(io.getStdErr().writer(), err) catch {}; 30 diag.report(io.getStdErr().writer(), err) catch {};