diff options
| author | 2022-02-25 19:44:52 +0100 | |
|---|---|---|
| committer | 2022-02-25 19:44:52 +0100 | |
| commit | c06c93608cb3befe77c78ba25c70b14db6f7b319 (patch) | |
| tree | 3598bbd00512eb5baa6da004ae7e42cd8005c3eb /example | |
| parent | Change clap into generating a struct (diff) | |
| download | zig-clap-c06c93608cb3befe77c78ba25c70b14db6f7b319.tar.gz zig-clap-c06c93608cb3befe77c78ba25c70b14db6f7b319.tar.xz zig-clap-c06c93608cb3befe77c78ba25c70b14db6f7b319.zip | |
Revert "Change clap into generating a struct"
This reverts commit cfaac64c404fb1c2e892880410aa3b7dd881ea58.
Diffstat (limited to '')
| -rw-r--r-- | example/README.md.template | 4 | ||||
| -rw-r--r-- | example/help.zig | 10 | ||||
| -rw-r--r-- | example/simple-ex.zig | 20 | ||||
| -rw-r--r-- | example/simple.zig | 20 | ||||
| -rw-r--r-- | example/streaming-clap.zig | 2 | ||||
| -rw-r--r-- | example/usage.zig | 12 |
6 files changed, 34 insertions, 34 deletions
diff --git a/example/README.md.template b/example/README.md.template index d792152..7f5c545 100644 --- a/example/README.md.template +++ b/example/README.md.template | |||
| @@ -51,9 +51,9 @@ zig-clap/example/simple-error.zig:16:18: note: called from here | |||
| 51 | 51 | ||
| 52 | There is also a `parseEx` variant that takes an argument iterator. | 52 | There is also a `parseEx` variant that takes an argument iterator. |
| 53 | 53 | ||
| 54 | ### `streaming.Clap` | 54 | ### `StreamingClap` |
| 55 | 55 | ||
| 56 | The `streaming.Clap` is the base of all the other parsers. It's a streaming parser that uses an | 56 | The `StreamingClap` is the base of all the other parsers. It's a streaming parser that uses an |
| 57 | `args.Iterator` to provide it with arguments lazily. | 57 | `args.Iterator` to provide it with arguments lazily. |
| 58 | 58 | ||
| 59 | ```zig | 59 | ```zig |
diff --git a/example/help.zig b/example/help.zig index 2e7ca2b..de3b707 100644 --- a/example/help.zig +++ b/example/help.zig | |||
| @@ -3,16 +3,16 @@ const std = @import("std"); | |||
| 3 | 3 | ||
| 4 | pub fn main() !void { | 4 | pub fn main() !void { |
| 5 | const params = comptime [_]clap.Param(clap.Help){ | 5 | const params = comptime [_]clap.Param(clap.Help){ |
| 6 | clap.untyped.parseParam("-h, --help Display this help and exit. ") catch unreachable, | 6 | clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, |
| 7 | clap.untyped.parseParam("-v, --version Output version information and exit.") catch unreachable, | 7 | clap.parseParam("-v, --version Output version information and exit.") catch unreachable, |
| 8 | }; | 8 | }; |
| 9 | 9 | ||
| 10 | var res = try clap.untyped.parse(clap.Help, ¶ms, .{}); | 10 | var args = try clap.parse(clap.Help, ¶ms, .{}); |
| 11 | defer res.deinit(); | 11 | defer args.deinit(); |
| 12 | 12 | ||
| 13 | // clap.help is a function that can print a simple help message, given a | 13 | // clap.help is a function that can print a simple help message, given a |
| 14 | // slice of Param(Help). There is also a helpEx, which can print a | 14 | // slice of Param(Help). There is also a helpEx, which can print a |
| 15 | // help message for any Param, but it is more verbose to call. | 15 | // help message for any Param, but it is more verbose to call. |
| 16 | if (res.args.help) | 16 | if (args.flag("--help")) |
| 17 | return clap.help(std.io.getStdErr().writer(), ¶ms); | 17 | return clap.help(std.io.getStdErr().writer(), ¶ms); |
| 18 | } | 18 | } |
diff --git a/example/simple-ex.zig b/example/simple-ex.zig index f1a958d..d2dc77e 100644 --- a/example/simple-ex.zig +++ b/example/simple-ex.zig | |||
| @@ -11,10 +11,10 @@ pub fn main() !void { | |||
| 11 | // First we specify what parameters our program can take. | 11 | // First we specify what parameters our program can take. |
| 12 | // We can use `parseParam` to parse a string to a `Param(Help)` | 12 | // We can use `parseParam` to parse a string to a `Param(Help)` |
| 13 | const params = comptime [_]clap.Param(clap.Help){ | 13 | const params = comptime [_]clap.Param(clap.Help){ |
| 14 | clap.untyped.parseParam("-h, --help Display this help and exit.") catch unreachable, | 14 | clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, |
| 15 | clap.untyped.parseParam("-n, --number <NUM> An option parameter, which takes a value.") catch unreachable, | 15 | clap.parseParam("-n, --number <NUM> An option parameter, which takes a value.") catch unreachable, |
| 16 | clap.untyped.parseParam("-s, --string <STR>... An option parameter which can be specified multiple times.") catch unreachable, | 16 | clap.parseParam("-s, --string <STR>... An option parameter which can be specified multiple times.") catch unreachable, |
| 17 | clap.untyped.parseParam("<POS>...") catch unreachable, | 17 | clap.parseParam("<POS>...") catch unreachable, |
| 18 | }; | 18 | }; |
| 19 | 19 | ||
| 20 | var iter = try process.ArgIterator.initWithAllocator(allocator); | 20 | var iter = try process.ArgIterator.initWithAllocator(allocator); |
| @@ -27,7 +27,7 @@ pub fn main() !void { | |||
| 27 | // This is optional. You can also pass `.{}` to `clap.parse` if you don't | 27 | // This is optional. You can also pass `.{}` to `clap.parse` if you don't |
| 28 | // care about the extra information `Diagnostics` provides. | 28 | // care about the extra information `Diagnostics` provides. |
| 29 | var diag = clap.Diagnostic{}; | 29 | var diag = clap.Diagnostic{}; |
| 30 | var res = clap.untyped.parseEx(clap.Help, ¶ms, &iter, .{ | 30 | var args = clap.parseEx(clap.Help, ¶ms, &iter, .{ |
| 31 | .allocator = allocator, | 31 | .allocator = allocator, |
| 32 | .diagnostic = &diag, | 32 | .diagnostic = &diag, |
| 33 | }) catch |err| { | 33 | }) catch |err| { |
| @@ -35,14 +35,14 @@ pub fn main() !void { | |||
| 35 | diag.report(io.getStdErr().writer(), err) catch {}; | 35 | diag.report(io.getStdErr().writer(), err) catch {}; |
| 36 | return err; | 36 | return err; |
| 37 | }; | 37 | }; |
| 38 | defer res.deinit(); | 38 | defer args.deinit(); |
| 39 | 39 | ||
| 40 | if (res.args.help) | 40 | if (args.flag("--help")) |
| 41 | debug.print("--help\n", .{}); | 41 | debug.print("--help\n", .{}); |
| 42 | if (res.args.number) |n| | 42 | if (args.option("--number")) |n| |
| 43 | debug.print("--number = {s}\n", .{n}); | 43 | debug.print("--number = {s}\n", .{n}); |
| 44 | for (res.args.string) |s| | 44 | for (args.options("--string")) |s| |
| 45 | debug.print("--string = {s}\n", .{s}); | 45 | debug.print("--string = {s}\n", .{s}); |
| 46 | for (res.positionals) |pos| | 46 | for (args.positionals()) |pos| |
| 47 | debug.print("{s}\n", .{pos}); | 47 | debug.print("{s}\n", .{pos}); |
| 48 | } | 48 | } |
diff --git a/example/simple.zig b/example/simple.zig index c37e896..ff6d301 100644 --- a/example/simple.zig +++ b/example/simple.zig | |||
| @@ -8,29 +8,29 @@ pub fn main() !void { | |||
| 8 | // First we specify what parameters our program can take. | 8 | // First we specify what parameters our program can take. |
| 9 | // We can use `parseParam` to parse a string to a `Param(Help)` | 9 | // We can use `parseParam` to parse a string to a `Param(Help)` |
| 10 | const params = comptime [_]clap.Param(clap.Help){ | 10 | const params = comptime [_]clap.Param(clap.Help){ |
| 11 | clap.untyped.parseParam("-h, --help Display this help and exit.") catch unreachable, | 11 | clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, |
| 12 | clap.untyped.parseParam("-n, --number <NUM> An option parameter, which takes a value.") catch unreachable, | 12 | clap.parseParam("-n, --number <NUM> An option parameter, which takes a value.") catch unreachable, |
| 13 | clap.untyped.parseParam("-s, --string <STR>... An option parameter which can be specified multiple times.") catch unreachable, | 13 | clap.parseParam("-s, --string <STR>... An option parameter which can be specified multiple times.") catch unreachable, |
| 14 | clap.untyped.parseParam("<POS>...") catch unreachable, | 14 | clap.parseParam("<POS>...") catch unreachable, |
| 15 | }; | 15 | }; |
| 16 | 16 | ||
| 17 | // Initalize our diagnostics, which can be used for reporting useful errors. | 17 | // Initalize our diagnostics, which can be used for reporting useful errors. |
| 18 | // This is optional. You can also pass `.{}` to `clap.parse` if you don't | 18 | // This is optional. You can also pass `.{}` to `clap.parse` if you don't |
| 19 | // care about the extra information `Diagnostics` provides. | 19 | // care about the extra information `Diagnostics` provides. |
| 20 | var diag = clap.Diagnostic{}; | 20 | var diag = clap.Diagnostic{}; |
| 21 | var res = clap.untyped.parse(clap.Help, ¶ms, .{ .diagnostic = &diag }) catch |err| { | 21 | var args = clap.parse(clap.Help, ¶ms, .{ .diagnostic = &diag }) catch |err| { |
| 22 | // Report useful error and exit | 22 | // Report useful error and exit |
| 23 | diag.report(io.getStdErr().writer(), err) catch {}; | 23 | diag.report(io.getStdErr().writer(), err) catch {}; |
| 24 | return err; | 24 | return err; |
| 25 | }; | 25 | }; |
| 26 | defer res.deinit(); | 26 | defer args.deinit(); |
| 27 | 27 | ||
| 28 | if (res.args.help) | 28 | if (args.flag("--help")) |
| 29 | debug.print("--help\n", .{}); | 29 | debug.print("--help\n", .{}); |
| 30 | if (res.args.number) |n| | 30 | if (args.option("--number")) |n| |
| 31 | debug.print("--number = {s}\n", .{n}); | 31 | debug.print("--number = {s}\n", .{n}); |
| 32 | for (res.args.string) |s| | 32 | for (args.options("--string")) |s| |
| 33 | debug.print("--string = {s}\n", .{s}); | 33 | debug.print("--string = {s}\n", .{s}); |
| 34 | for (res.positionals) |pos| | 34 | for (args.positionals()) |pos| |
| 35 | debug.print("{s}\n", .{pos}); | 35 | debug.print("{s}\n", .{pos}); |
| 36 | } | 36 | } |
diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig index cacda56..a7ab7d8 100644 --- a/example/streaming-clap.zig +++ b/example/streaming-clap.zig | |||
| @@ -32,7 +32,7 @@ pub fn main() !void { | |||
| 32 | // This is optional. You can also leave the `diagnostic` field unset if you | 32 | // This is optional. You can also leave the `diagnostic` field unset if you |
| 33 | // don't care about the extra information `Diagnostic` provides. | 33 | // don't care about the extra information `Diagnostic` provides. |
| 34 | var diag = clap.Diagnostic{}; | 34 | var diag = clap.Diagnostic{}; |
| 35 | var parser = clap.streaming.Clap(u8, process.ArgIterator){ | 35 | var parser = clap.StreamingClap(u8, process.ArgIterator){ |
| 36 | .params = ¶ms, | 36 | .params = ¶ms, |
| 37 | .iter = &iter, | 37 | .iter = &iter, |
| 38 | .diagnostic = &diag, | 38 | .diagnostic = &diag, |
diff --git a/example/usage.zig b/example/usage.zig index 04fedba..368a6b3 100644 --- a/example/usage.zig +++ b/example/usage.zig | |||
| @@ -3,17 +3,17 @@ const std = @import("std"); | |||
| 3 | 3 | ||
| 4 | pub fn main() !void { | 4 | pub fn main() !void { |
| 5 | const params = comptime [_]clap.Param(clap.Help){ | 5 | const params = comptime [_]clap.Param(clap.Help){ |
| 6 | clap.untyped.parseParam("-h, --help Display this help and exit.") catch unreachable, | 6 | clap.parseParam("-h, --help Display this help and exit. ") catch unreachable, |
| 7 | clap.untyped.parseParam("-v, --version Output version information and exit.") catch unreachable, | 7 | clap.parseParam("-v, --version Output version information and exit. ") catch unreachable, |
| 8 | clap.untyped.parseParam(" --value <N> An option parameter, which takes a value.") catch unreachable, | 8 | clap.parseParam(" --value <N> An option parameter, which takes a value.") catch unreachable, |
| 9 | }; | 9 | }; |
| 10 | 10 | ||
| 11 | var res = try clap.untyped.parse(clap.Help, ¶ms, .{}); | 11 | var args = try clap.parse(clap.Help, ¶ms, .{}); |
| 12 | defer res.deinit(); | 12 | defer args.deinit(); |
| 13 | 13 | ||
| 14 | // clap.usage is a function that can print a simple usage message, given a | 14 | // clap.usage is a function that can print a simple usage message, given a |
| 15 | // slice of Param(Help). There is also a usageEx, which can print a | 15 | // slice of Param(Help). There is also a usageEx, which can print a |
| 16 | // usage message for any Param, but it is more verbose to call. | 16 | // usage message for any Param, but it is more verbose to call. |
| 17 | if (res.args.help) | 17 | if (args.flag("--help")) |
| 18 | return clap.usage(std.io.getStdErr().writer(), ¶ms); | 18 | return clap.usage(std.io.getStdErr().writer(), ¶ms); |
| 19 | } | 19 | } |