summaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/help.zig7
-rw-r--r--example/simple-ex.zig4
-rw-r--r--example/simple.zig4
-rw-r--r--example/usage.zig7
4 files changed, 20 insertions, 2 deletions
diff --git a/example/help.zig b/example/help.zig
index e83ae44..2f063c5 100644
--- a/example/help.zig
+++ b/example/help.zig
@@ -2,13 +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 var gpa = std.heap.GeneralPurposeAllocator(.{}){};
6 defer _ = gpa.deinit();
7
5 const params = comptime clap.parseParamsComptime( 8 const params = comptime clap.parseParamsComptime(
6 \\-h, --help Display this help and exit. 9 \\-h, --help Display this help and exit.
7 \\-v, --version Output version information and exit. 10 \\-v, --version Output version information and exit.
8 \\ 11 \\
9 ); 12 );
10 13
11 var res = try clap.parse(clap.Help, &params, clap.parsers.default, .{}); 14 var res = try clap.parse(clap.Help, &params, clap.parsers.default, .{
15 .allocator = gpa.allocator(),
16 });
12 defer res.deinit(); 17 defer res.deinit();
13 18
14 // `clap.help` is a function that can print a simple help message. It can print any `Param` 19 // `clap.help` is a function that can print a simple help message. It can print any `Param`
diff --git a/example/simple-ex.zig b/example/simple-ex.zig
index dd5d929..436d058 100644
--- a/example/simple-ex.zig
+++ b/example/simple-ex.zig
@@ -6,6 +6,9 @@ const io = std.io;
6const process = std.process; 6const process = std.process;
7 7
8pub fn main() !void { 8pub fn main() !void {
9 var gpa = std.heap.GeneralPurposeAllocator(.{}){};
10 defer _ = gpa.deinit();
11
9 // First we specify what parameters our program can take. 12 // First we specify what parameters our program can take.
10 // We can use `parseParamsComptime` to parse a string into an array of `Param(Help)` 13 // We can use `parseParamsComptime` to parse a string into an array of `Param(Help)`
11 const params = comptime clap.parseParamsComptime( 14 const params = comptime clap.parseParamsComptime(
@@ -30,6 +33,7 @@ pub fn main() !void {
30 var diag = clap.Diagnostic{}; 33 var diag = clap.Diagnostic{};
31 var res = clap.parse(clap.Help, &params, parsers, .{ 34 var res = clap.parse(clap.Help, &params, parsers, .{
32 .diagnostic = &diag, 35 .diagnostic = &diag,
36 .allocator = gpa.allocator(),
33 }) catch |err| { 37 }) catch |err| {
34 diag.report(io.getStdErr().writer(), err) catch {}; 38 diag.report(io.getStdErr().writer(), err) catch {};
35 return err; 39 return err;
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 {};
diff --git a/example/usage.zig b/example/usage.zig
index 333536b..a773dd2 100644
--- a/example/usage.zig
+++ b/example/usage.zig
@@ -2,6 +2,9 @@ const clap = @import("clap");
2const std = @import("std"); 2const std = @import("std");
3 3
4pub fn main() !void { 4pub fn main() !void {
5 var gpa = std.heap.GeneralPurposeAllocator(.{}){};
6 defer _ = gpa.deinit();
7
5 const params = comptime clap.parseParamsComptime( 8 const params = comptime clap.parseParamsComptime(
6 \\-h, --help Display this help and exit. 9 \\-h, --help Display this help and exit.
7 \\-v, --version Output version information and exit. 10 \\-v, --version Output version information and exit.
@@ -9,7 +12,9 @@ pub fn main() !void {
9 \\ 12 \\
10 ); 13 );
11 14
12 var res = try clap.parse(clap.Help, &params, clap.parsers.default, .{}); 15 var res = try clap.parse(clap.Help, &params, clap.parsers.default, .{
16 .allocator = gpa.allocator(),
17 });
13 defer res.deinit(); 18 defer res.deinit();
14 19
15 // `clap.usage` is a function that can print a simple help message. It can print any `Param` 20 // `clap.usage` is a function that can print a simple help message. It can print any `Param`