summaryrefslogtreecommitdiff
path: root/example/streaming-clap.zig
diff options
context:
space:
mode:
authorGravatar Komari Spaghetti2021-05-08 18:08:52 +0200
committerGravatar Komari Spaghetti2021-05-08 18:08:52 +0200
commit4c14bfd5188bb61d7076bc33fccbcc6a5e9dac01 (patch)
tree8f5267e4da9bbc14bd595697797457911d4b3081 /example/streaming-clap.zig
parentRefactor Diagnostic (and others) into a ParseOption struct (diff)
downloadzig-clap-4c14bfd5188bb61d7076bc33fccbcc6a5e9dac01.tar.gz
zig-clap-4c14bfd5188bb61d7076bc33fccbcc6a5e9dac01.tar.xz
zig-clap-4c14bfd5188bb61d7076bc33fccbcc6a5e9dac01.zip
Modernize codebase
* Better naming for variables * Follow naming style of enums * Use `writer()` instead of `outStream()` * Change many initializers to be a one liner * Don't explicitly initialize fields to their default value
Diffstat (limited to 'example/streaming-clap.zig')
-rw-r--r--example/streaming-clap.zig18
1 files changed, 8 insertions, 10 deletions
diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig
index f8d873d..41efd1f 100644
--- a/example/streaming-clap.zig
+++ b/example/streaming-clap.zig
@@ -2,25 +2,23 @@ const clap = @import("clap");
2const std = @import("std"); 2const std = @import("std");
3 3
4const debug = std.debug; 4const debug = std.debug;
5const io = std.io;
5 6
6pub fn main() !void { 7pub fn main() !void {
7 const allocator = std.heap.page_allocator; 8 const allocator = std.heap.page_allocator;
8 9
9 // First we specify what parameters our program can take. 10 // First we specify what parameters our program can take.
10 const params = [_]clap.Param(u8){ 11 const params = [_]clap.Param(u8){
11 clap.Param(u8){ 12 .{
12 .id = 'h', 13 .id = 'h',
13 .names = clap.Names{ .short = 'h', .long = "help" }, 14 .names = .{ .short = 'h', .long = "help" },
14 }, 15 },
15 clap.Param(u8){ 16 .{
16 .id = 'n', 17 .id = 'n',
17 .names = clap.Names{ .short = 'n', .long = "number" }, 18 .names = .{ .short = 'n', .long = "number" },
18 .takes_value = .One, 19 .takes_value = .one,
19 },
20 clap.Param(u8){
21 .id = 'f',
22 .takes_value = .One,
23 }, 20 },
21 .{ .id = 'f', .takes_value = .one },
24 }; 22 };
25 23
26 // We then initialize an argument iterator. We will use the OsIterator as it nicely 24 // We then initialize an argument iterator. We will use the OsIterator as it nicely
@@ -41,7 +39,7 @@ pub fn main() !void {
41 // Because we use a streaming parser, we have to consume each argument parsed individually. 39 // Because we use a streaming parser, we have to consume each argument parsed individually.
42 while (parser.next() catch |err| { 40 while (parser.next() catch |err| {
43 // Report useful error and exit 41 // Report useful error and exit
44 diag.report(std.io.getStdErr().outStream(), err) catch {}; 42 diag.report(io.getStdErr().writer(), err) catch {};
45 return err; 43 return err;
46 }) |arg| { 44 }) |arg| {
47 // arg.param will point to the parameter which matched the argument. 45 // arg.param will point to the parameter which matched the argument.