summaryrefslogtreecommitdiff
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/help.zig7
-rw-r--r--example/simple-error.zig4
-rw-r--r--example/simple-ex.zig3
-rw-r--r--example/simple.zig3
-rw-r--r--example/streaming-clap.zig18
-rw-r--r--example/usage.zig6
6 files changed, 18 insertions, 23 deletions
diff --git a/example/help.zig b/example/help.zig
index 2775177..3cf9e42 100644
--- a/example/help.zig
+++ b/example/help.zig
@@ -1,15 +1,12 @@
1const std = @import("std");
2const clap = @import("clap"); 1const clap = @import("clap");
2const std = @import("std");
3 3
4pub fn main() !void { 4pub fn main() !void {
5 const stderr_file = std.io.getStdErr();
6 var stderr_out_stream = stderr_file.outStream();
7
8 // clap.help is a function that can print a simple help message, given a 5 // clap.help is a function that can print a simple help message, given a
9 // slice of Param(Help). There is also a helpEx, which can print a 6 // slice of Param(Help). There is also a helpEx, which can print a
10 // help message for any Param, but it is more verbose to call. 7 // help message for any Param, but it is more verbose to call.
11 try clap.help( 8 try clap.help(
12 stderr_out_stream, 9 std.io.getStdErr().writer(),
13 comptime &[_]clap.Param(clap.Help){ 10 comptime &[_]clap.Param(clap.Help){
14 clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, 11 clap.parseParam("-h, --help Display this help and exit. ") catch unreachable,
15 clap.parseParam("-v, --version Output version information and exit.") catch unreachable, 12 clap.parseParam("-v, --version Output version information and exit.") catch unreachable,
diff --git a/example/simple-error.zig b/example/simple-error.zig
index 3c62f0e..c04a9c6 100644
--- a/example/simple-error.zig
+++ b/example/simple-error.zig
@@ -1,12 +1,12 @@
1const std = @import("std");
2const clap = @import("clap"); 1const clap = @import("clap");
2const std = @import("std");
3 3
4pub fn main() !void { 4pub fn main() !void {
5 const params = comptime [_]clap.Param(clap.Help){ 5 const params = comptime [_]clap.Param(clap.Help){
6 clap.parseParam("-h, --help Display this help and exit.") catch unreachable, 6 clap.parseParam("-h, --help Display this help and exit.") catch unreachable,
7 }; 7 };
8 8
9 var args = try clap.parse(clap.Help, &params, std.heap.direct_allocator, null); 9 var args = try clap.parse(clap.Help, &params, .{});
10 defer args.deinit(); 10 defer args.deinit();
11 11
12 _ = args.flag("--helps"); 12 _ = args.flag("--helps");
diff --git a/example/simple-ex.zig b/example/simple-ex.zig
index f504d63..f08751b 100644
--- a/example/simple-ex.zig
+++ b/example/simple-ex.zig
@@ -2,6 +2,7 @@ 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;
@@ -29,7 +30,7 @@ pub fn main() !void {
29 .diagnostic = &diag, 30 .diagnostic = &diag,
30 }) catch |err| { 31 }) catch |err| {
31 // Report useful error and exit 32 // Report useful error and exit
32 diag.report(std.io.getStdErr().outStream(), err) catch {}; 33 diag.report(io.getStdErr().writer(), err) catch {};
33 return err; 34 return err;
34 }; 35 };
35 defer args.deinit(); 36 defer args.deinit();
diff --git a/example/simple.zig b/example/simple.zig
index 392dca3..69473fa 100644
--- a/example/simple.zig
+++ b/example/simple.zig
@@ -2,6 +2,7 @@ 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 // First we specify what parameters our program can take. 8 // First we specify what parameters our program can take.
@@ -19,7 +20,7 @@ pub fn main() !void {
19 var diag = clap.Diagnostic{}; 20 var diag = clap.Diagnostic{};
20 var args = clap.parse(clap.Help, &params, .{ .diagnostic = &diag }) catch |err| { 21 var args = clap.parse(clap.Help, &params, .{ .diagnostic = &diag }) catch |err| {
21 // Report useful error and exit 22 // Report useful error and exit
22 diag.report(std.io.getStdErr().outStream(), err) catch {}; 23 diag.report(io.getStdErr().writer(), err) catch {};
23 return err; 24 return err;
24 }; 25 };
25 defer args.deinit(); 26 defer args.deinit();
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.
diff --git a/example/usage.zig b/example/usage.zig
index 25e1a34..e044f1d 100644
--- a/example/usage.zig
+++ b/example/usage.zig
@@ -1,14 +1,12 @@
1const std = @import("std");
2const clap = @import("clap"); 1const clap = @import("clap");
2const std = @import("std");
3 3
4pub fn main() !void { 4pub fn main() !void {
5 const stderr = std.io.getStdErr().outStream();
6
7 // clap.usage is a function that can print a simple usage message, given a 5 // clap.usage is a function that can print a simple usage message, given a
8 // slice of Param(Help). There is also a usageEx, which can print a 6 // slice of Param(Help). There is also a usageEx, which can print a
9 // usage message for any Param, but it is more verbose to call. 7 // usage message for any Param, but it is more verbose to call.
10 try clap.usage( 8 try clap.usage(
11 stderr, 9 std.io.getStdErr().writer(),
12 comptime &[_]clap.Param(clap.Help){ 10 comptime &[_]clap.Param(clap.Help){
13 clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, 11 clap.parseParam("-h, --help Display this help and exit. ") catch unreachable,
14 clap.parseParam("-v, --version Output version information and exit.") catch unreachable, 12 clap.parseParam("-v, --version Output version information and exit.") catch unreachable,