summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md26
1 files changed, 12 insertions, 14 deletions
diff --git a/README.md b/README.md
index 3156539..ad9f026 100644
--- a/README.md
+++ b/README.md
@@ -25,8 +25,8 @@ into master on every `zig` release.
25The simplest way to use this library is to just call the `clap.parse` function. 25The simplest way to use this library is to just call the `clap.parse` function.
26 26
27```zig 27```zig
28const std = @import("std");
29const clap = @import("clap"); 28const clap = @import("clap");
29const std = @import("std");
30 30
31const debug = std.debug; 31const debug = std.debug;
32 32
@@ -41,11 +41,10 @@ pub fn main() !void {
41 }; 41 };
42 42
43 // Initalize our diagnostics, which can be used for reporting useful errors. 43 // Initalize our diagnostics, which can be used for reporting useful errors.
44 // This is optional. You can also just pass `null` to `parser.next` if you 44 // This is optional. You can also pass `.{}` to `clap.parse` if you don't
45 // don't care about the extra information `Diagnostics` provides. 45 // care about the extra information `Diagnostics` provides.
46 var diag: clap.Diagnostic = undefined; 46 var diag = clap.Diagnostic{};
47 47 var args = clap.parse(clap.Help, &params, .{ .diagnostic = &diag }) catch |err| {
48 var args = clap.parse(clap.Help, &params, std.heap.page_allocator, &diag) catch |err| {
49 // Report useful error and exit 48 // Report useful error and exit
50 diag.report(std.io.getStdErr().outStream(), err) catch {}; 49 diag.report(std.io.getStdErr().outStream(), err) catch {};
51 return err; 50 return err;
@@ -107,8 +106,8 @@ The `StreamingClap` is the base of all the other parsers. It's a streaming parse
107`args.Iterator` to provide it with arguments lazily. 106`args.Iterator` to provide it with arguments lazily.
108 107
109```zig 108```zig
110const std = @import("std");
111const clap = @import("clap"); 109const clap = @import("clap");
110const std = @import("std");
112 111
113const debug = std.debug; 112const debug = std.debug;
114 113
@@ -137,19 +136,18 @@ pub fn main() !void {
137 var iter = try clap.args.OsIterator.init(allocator); 136 var iter = try clap.args.OsIterator.init(allocator);
138 defer iter.deinit(); 137 defer iter.deinit();
139 138
140 // Initialize our streaming parser. 139 // Initalize our diagnostics, which can be used for reporting useful errors.
140 // This is optional. You can also leave the `diagnostic` field unset if you
141 // don't care about the extra information `Diagnostic` provides.
142 var diag = clap.Diagnostic{};
141 var parser = clap.StreamingClap(u8, clap.args.OsIterator){ 143 var parser = clap.StreamingClap(u8, clap.args.OsIterator){
142 .params = &params, 144 .params = &params,
143 .iter = &iter, 145 .iter = &iter,
146 .diagnostic = &diag,
144 }; 147 };
145 148
146 // Initalize our diagnostics, which can be used for reporting useful errors.
147 // This is optional. You can also just pass `null` to `parser.next` if you
148 // don't care about the extra information `Diagnostics` provides.
149 var diag: clap.Diagnostic = undefined;
150
151 // Because we use a streaming parser, we have to consume each argument parsed individually. 149 // Because we use a streaming parser, we have to consume each argument parsed individually.
152 while (parser.next(&diag) catch |err| { 150 while (parser.next() catch |err| {
153 // Report useful error and exit 151 // Report useful error and exit
154 diag.report(std.io.getStdErr().outStream(), err) catch {}; 152 diag.report(std.io.getStdErr().outStream(), err) catch {};
155 return err; 153 return err;