diff options
| author | 2025-07-20 21:40:56 +0200 | |
|---|---|---|
| committer | 2025-07-21 18:52:54 +0200 | |
| commit | 6f103922a8133ba11773e6ad9a52e26e1d99b3e7 (patch) | |
| tree | 66bc5fa5fc36f20575be1e1a59ff890ab9c8b23e /example | |
| parent | chore: Update setup-zig to v2 (diff) | |
| download | zig-clap-6f103922a8133ba11773e6ad9a52e26e1d99b3e7.tar.gz zig-clap-6f103922a8133ba11773e6ad9a52e26e1d99b3e7.tar.xz zig-clap-6f103922a8133ba11773e6ad9a52e26e1d99b3e7.zip | |
Update to Zig 0.15.0-dev.1147
Diffstat (limited to 'example')
| -rw-r--r-- | example/help.zig | 8 | ||||
| -rw-r--r-- | example/simple-ex.zig | 6 | ||||
| -rw-r--r-- | example/simple.zig | 6 | ||||
| -rw-r--r-- | example/streaming-clap.zig | 6 | ||||
| -rw-r--r-- | example/subcommands.zig | 13 | ||||
| -rw-r--r-- | example/usage.zig | 9 |
6 files changed, 35 insertions, 13 deletions
diff --git a/example/help.zig b/example/help.zig index b80ee35..676a56a 100644 --- a/example/help.zig +++ b/example/help.zig | |||
| @@ -17,8 +17,12 @@ pub fn main() !void { | |||
| 17 | // where `Id` has a `description` and `value` method (`Param(Help)` is one such parameter). | 17 | // where `Id` has a `description` and `value` method (`Param(Help)` is one such parameter). |
| 18 | // The last argument contains options as to how `help` should print those parameters. Using | 18 | // The last argument contains options as to how `help` should print those parameters. Using |
| 19 | // `.{}` means the default options. | 19 | // `.{}` means the default options. |
| 20 | if (res.args.help != 0) | 20 | if (res.args.help != 0) { |
| 21 | return clap.help(std.io.getStdErr().writer(), clap.Help, ¶ms, .{}); | 21 | var buf: [1024]u8 = undefined; |
| 22 | var stderr = std.fs.File.stderr().writer(&buf); | ||
| 23 | try clap.help(&stderr.interface, clap.Help, ¶ms, .{}); | ||
| 24 | return stderr.interface.flush(); | ||
| 25 | } | ||
| 22 | } | 26 | } |
| 23 | 27 | ||
| 24 | const clap = @import("clap"); | 28 | const clap = @import("clap"); |
diff --git a/example/simple-ex.zig b/example/simple-ex.zig index 22f657f..a993868 100644 --- a/example/simple-ex.zig +++ b/example/simple-ex.zig | |||
| @@ -31,7 +31,11 @@ pub fn main() !void { | |||
| 31 | // allowed. | 31 | // allowed. |
| 32 | .assignment_separators = "=:", | 32 | .assignment_separators = "=:", |
| 33 | }) catch |err| { | 33 | }) catch |err| { |
| 34 | diag.report(std.io.getStdErr().writer(), err) catch {}; | 34 | // Report useful error and exit. |
| 35 | var buf: [1024]u8 = undefined; | ||
| 36 | var stderr = std.fs.File.stderr().writer(&buf); | ||
| 37 | try diag.report(&stderr.interface, err); | ||
| 38 | try stderr.interface.flush(); | ||
| 35 | return err; | 39 | return err; |
| 36 | }; | 40 | }; |
| 37 | defer res.deinit(); | 41 | defer res.deinit(); |
diff --git a/example/simple.zig b/example/simple.zig index 2b7bf0a..ca6bd75 100644 --- a/example/simple.zig +++ b/example/simple.zig | |||
| @@ -21,8 +21,10 @@ pub fn main() !void { | |||
| 21 | .allocator = gpa.allocator(), | 21 | .allocator = gpa.allocator(), |
| 22 | }) catch |err| { | 22 | }) catch |err| { |
| 23 | // Report useful error and exit. | 23 | // Report useful error and exit. |
| 24 | diag.report(std.io.getStdErr().writer(), err) catch {}; | 24 | var buf: [1024]u8 = undefined; |
| 25 | return err; | 25 | var stderr = std.fs.File.stderr().writer(&buf); |
| 26 | try diag.report(&stderr.interface, err); | ||
| 27 | return stderr.interface.flush(); | ||
| 26 | }; | 28 | }; |
| 27 | defer res.deinit(); | 29 | defer res.deinit(); |
| 28 | 30 | ||
diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig index 054c401..d60167c 100644 --- a/example/streaming-clap.zig +++ b/example/streaming-clap.zig | |||
| @@ -34,8 +34,10 @@ pub fn main() !void { | |||
| 34 | // Because we use a streaming parser, we have to consume each argument parsed individually. | 34 | // Because we use a streaming parser, we have to consume each argument parsed individually. |
| 35 | while (parser.next() catch |err| { | 35 | while (parser.next() catch |err| { |
| 36 | // Report useful error and exit. | 36 | // Report useful error and exit. |
| 37 | diag.report(std.io.getStdErr().writer(), err) catch {}; | 37 | var buf: [1024]u8 = undefined; |
| 38 | return err; | 38 | var stderr = std.fs.File.stderr().writer(&buf); |
| 39 | try diag.report(&stderr.interface, err); | ||
| 40 | return stderr.interface.flush(); | ||
| 39 | }) |arg| { | 41 | }) |arg| { |
| 40 | // arg.param will point to the parameter which matched the argument. | 42 | // arg.param will point to the parameter which matched the argument. |
| 41 | switch (arg.param.id) { | 43 | switch (arg.param.id) { |
diff --git a/example/subcommands.zig b/example/subcommands.zig index 8223f31..644e371 100644 --- a/example/subcommands.zig +++ b/example/subcommands.zig | |||
| @@ -41,8 +41,10 @@ pub fn main() !void { | |||
| 41 | // not fully consumed. It can then be reused to parse the arguments for subcommands. | 41 | // not fully consumed. It can then be reused to parse the arguments for subcommands. |
| 42 | .terminating_positional = 0, | 42 | .terminating_positional = 0, |
| 43 | }) catch |err| { | 43 | }) catch |err| { |
| 44 | diag.report(std.io.getStdErr().writer(), err) catch {}; | 44 | var buf: [1024]u8 = undefined; |
| 45 | return err; | 45 | var stderr = std.fs.File.stderr().writer(&buf); |
| 46 | try diag.report(&stderr.interface, err); | ||
| 47 | return stderr.interface.flush(); | ||
| 46 | }; | 48 | }; |
| 47 | defer res.deinit(); | 49 | defer res.deinit(); |
| 48 | 50 | ||
| @@ -77,8 +79,11 @@ fn mathMain(gpa: std.mem.Allocator, iter: *std.process.ArgIterator, main_args: M | |||
| 77 | .diagnostic = &diag, | 79 | .diagnostic = &diag, |
| 78 | .allocator = gpa, | 80 | .allocator = gpa, |
| 79 | }) catch |err| { | 81 | }) catch |err| { |
| 80 | diag.report(std.io.getStdErr().writer(), err) catch {}; | 82 | var buf: [1024]u8 = undefined; |
| 81 | return err; | 83 | var stderr = std.fs.File.stderr().writer(&buf); |
| 84 | try diag.report(&stderr.interface, err); | ||
| 85 | try stderr.interface.flush(); | ||
| 86 | return err; // propagate error | ||
| 82 | }; | 87 | }; |
| 83 | defer res.deinit(); | 88 | defer res.deinit(); |
| 84 | 89 | ||
diff --git a/example/usage.zig b/example/usage.zig index 59ac84a..8bd25b7 100644 --- a/example/usage.zig +++ b/example/usage.zig | |||
| @@ -16,8 +16,13 @@ pub fn main() !void { | |||
| 16 | 16 | ||
| 17 | // `clap.usage` is a function that can print a simple help message. It can print any `Param` | 17 | // `clap.usage` is a function that can print a simple help message. It can print any `Param` |
| 18 | // where `Id` has a `value` method (`Param(Help)` is one such parameter). | 18 | // where `Id` has a `value` method (`Param(Help)` is one such parameter). |
| 19 | if (res.args.help != 0) | 19 | if (res.args.help != 0) { |
| 20 | return clap.usage(std.io.getStdErr().writer(), clap.Help, ¶ms); | 20 | var buf: [1024]u8 = undefined; |
| 21 | var stderr = std.fs.File.stderr().writer(&buf); | ||
| 22 | clap.usage(&stderr.interface, clap.Help, ¶ms) catch {}; | ||
| 23 | try stderr.interface.flush(); | ||
| 24 | return; | ||
| 25 | } | ||
| 21 | } | 26 | } |
| 22 | 27 | ||
| 23 | const clap = @import("clap"); | 28 | const clap = @import("clap"); |