diff options
| author | 2024-11-25 07:57:42 +0000 | |
|---|---|---|
| committer | 2024-11-25 08:57:42 +0100 | |
| commit | 560c8dd72ab25d556123846254040c5bf9ad3ba4 (patch) | |
| tree | a5c57b24b67fdc1fc71abf444d422062453921be | |
| parent | refactor: switch on signedness (diff) | |
| download | zig-clap-560c8dd72ab25d556123846254040c5bf9ad3ba4.tar.gz zig-clap-560c8dd72ab25d556123846254040c5bf9ad3ba4.tar.xz zig-clap-560c8dd72ab25d556123846254040c5bf9ad3ba4.zip | |
Patch up README and fix comments in example files. (#143)
The readme was also reflowed to 100 cols. I probably should have put that in a separate commit but oh well. The comments were not subjected to reflowing (yet).
| -rw-r--r-- | README.md | 54 | ||||
| -rw-r--r-- | example/README.md.template | 28 | ||||
| -rw-r--r-- | example/simple-ex.zig | 2 | ||||
| -rw-r--r-- | example/simple.zig | 4 | ||||
| -rw-r--r-- | example/streaming-clap.zig | 4 | ||||
| -rw-r--r-- | example/subcommands.zig | 16 |
6 files changed, 52 insertions, 56 deletions
| @@ -45,8 +45,8 @@ exe.root_module.addImport("clap", clap.module("clap")); | |||
| 45 | 45 | ||
| 46 | ## API Reference | 46 | ## API Reference |
| 47 | 47 | ||
| 48 | Automatically generated API Reference for the project | 48 | Automatically generated API Reference for the project can be found at https://Hejsil.github.io/ |
| 49 | can be found at https://Hejsil.github.io/zig-clap. | 49 | zig-clap. |
| 50 | Note that Zig autodoc is in beta; the website may be broken or incomplete. | 50 | Note that Zig autodoc is in beta; the website may be broken or incomplete. |
| 51 | 51 | ||
| 52 | ## Examples | 52 | ## Examples |
| @@ -61,7 +61,7 @@ pub fn main() !void { | |||
| 61 | defer _ = gpa.deinit(); | 61 | defer _ = gpa.deinit(); |
| 62 | 62 | ||
| 63 | // First we specify what parameters our program can take. | 63 | // First we specify what parameters our program can take. |
| 64 | // We can use `parseParamsComptime` to parse a string into an array of `Param(Help)` | 64 | // We can use `parseParamsComptime` to parse a string into an array of `Param(Help)`. |
| 65 | const params = comptime clap.parseParamsComptime( | 65 | const params = comptime clap.parseParamsComptime( |
| 66 | \\-h, --help Display this help and exit. | 66 | \\-h, --help Display this help and exit. |
| 67 | \\-n, --number <usize> An option parameter, which takes a value. | 67 | \\-n, --number <usize> An option parameter, which takes a value. |
| @@ -78,7 +78,7 @@ pub fn main() !void { | |||
| 78 | .diagnostic = &diag, | 78 | .diagnostic = &diag, |
| 79 | .allocator = gpa.allocator(), | 79 | .allocator = gpa.allocator(), |
| 80 | }) catch |err| { | 80 | }) catch |err| { |
| 81 | // Report useful error and exit | 81 | // Report useful error and exit. |
| 82 | diag.report(std.io.getStdErr().writer(), err) catch {}; | 82 | diag.report(std.io.getStdErr().writer(), err) catch {}; |
| 83 | return err; | 83 | return err; |
| 84 | }; | 84 | }; |
| @@ -99,16 +99,16 @@ const std = @import("std"); | |||
| 99 | 99 | ||
| 100 | ``` | 100 | ``` |
| 101 | 101 | ||
| 102 | The result will contain an `args` field and a `positionals` field. `args` will have one field | 102 | The result will contain an `args` field and a `positionals` field. `args` will have one field for |
| 103 | for each none positional parameter of your program. The name of the field will be the longest | 103 | each non-positional parameter of your program. The name of the field will be the longest name of the |
| 104 | name of the parameter. `positionals` be a tuple with one field for each positional parameter. | 104 | parameter. `positionals` will be a tuple with one field for each positional parameter. |
| 105 | 105 | ||
| 106 | The fields in `args` and `postionals` are typed. The type is based on the name of the value the | 106 | The fields in `args` and `postionals` are typed. The type is based on the name of the value the |
| 107 | parameter takes. Since `--number` takes a `usize` the field `res.args.number` has the type `usize`. | 107 | parameter takes. Since `--number` takes a `usize` the field `res.args.number` has the type `usize`. |
| 108 | 108 | ||
| 109 | Note that this is only the case because `clap.parsers.default` has a field called `usize` which | 109 | Note that this is only the case because `clap.parsers.default` has a field called `usize` which |
| 110 | contains a parser that returns `usize`. You can pass in something other than | 110 | contains a parser that returns `usize`. You can pass in something other than `clap.parsers.default` |
| 111 | `clap.parsers.default` if you want some other mapping. | 111 | if you want some other mapping. |
| 112 | 112 | ||
| 113 | ```zig | 113 | ```zig |
| 114 | pub fn main() !void { | 114 | pub fn main() !void { |
| @@ -116,7 +116,7 @@ pub fn main() !void { | |||
| 116 | defer _ = gpa.deinit(); | 116 | defer _ = gpa.deinit(); |
| 117 | 117 | ||
| 118 | // First we specify what parameters our program can take. | 118 | // First we specify what parameters our program can take. |
| 119 | // We can use `parseParamsComptime` to parse a string into an array of `Param(Help)` | 119 | // We can use `parseParamsComptime` to parse a string into an array of `Param(Help)`. |
| 120 | const params = comptime clap.parseParamsComptime( | 120 | const params = comptime clap.parseParamsComptime( |
| 121 | \\-h, --help Display this help and exit. | 121 | \\-h, --help Display this help and exit. |
| 122 | \\-n, --number <INT> An option parameter, which takes a value. | 122 | \\-n, --number <INT> An option parameter, which takes a value. |
| @@ -172,7 +172,7 @@ There is an option for `clap.parse` and `clap.parseEx` called `terminating_posit | |||
| 172 | for users of `clap` to implement subcommands in their cli application: | 172 | for users of `clap` to implement subcommands in their cli application: |
| 173 | 173 | ||
| 174 | ```zig | 174 | ```zig |
| 175 | // These are our subcommands | 175 | // These are our subcommands. |
| 176 | const SubCommands = enum { | 176 | const SubCommands = enum { |
| 177 | help, | 177 | help, |
| 178 | math, | 178 | math, |
| @@ -182,7 +182,7 @@ const main_parsers = .{ | |||
| 182 | .command = clap.parsers.enumeration(SubCommands), | 182 | .command = clap.parsers.enumeration(SubCommands), |
| 183 | }; | 183 | }; |
| 184 | 184 | ||
| 185 | // The parameters for main. Parameters for the subcommands are specified further down | 185 | // The parameters for `main`. Parameters for the subcommands are specified further down. |
| 186 | const main_params = clap.parseParamsComptime( | 186 | const main_params = clap.parseParamsComptime( |
| 187 | \\-h, --help Display this help and exit. | 187 | \\-h, --help Display this help and exit. |
| 188 | \\<command> | 188 | \\<command> |
| @@ -190,7 +190,7 @@ const main_params = clap.parseParamsComptime( | |||
| 190 | ); | 190 | ); |
| 191 | 191 | ||
| 192 | // To pass around arguments returned by clap, `clap.Result` and `clap.ResultEx` can be used to | 192 | // To pass around arguments returned by clap, `clap.Result` and `clap.ResultEx` can be used to |
| 193 | // get the return type of `clap.parse` and `clap.parseEx` | 193 | // get the return type of `clap.parse` and `clap.parseEx`. |
| 194 | const MainArgs = clap.ResultEx(clap.Help, &main_params, main_parsers); | 194 | const MainArgs = clap.ResultEx(clap.Help, &main_params, main_parsers); |
| 195 | 195 | ||
| 196 | pub fn main() !void { | 196 | pub fn main() !void { |
| @@ -212,7 +212,7 @@ pub fn main() !void { | |||
| 212 | // here because parsed positionals are, like slices and arrays, indexed starting at 0). | 212 | // here because parsed positionals are, like slices and arrays, indexed starting at 0). |
| 213 | // | 213 | // |
| 214 | // This will terminate the parsing after parsing the subcommand enum and leave `iter` | 214 | // This will terminate the parsing after parsing the subcommand enum and leave `iter` |
| 215 | // not fully consumed. It can then be reused to parse the arguments for subcommands | 215 | // not fully consumed. It can then be reused to parse the arguments for subcommands. |
| 216 | .terminating_positional = 0, | 216 | .terminating_positional = 0, |
| 217 | }) catch |err| { | 217 | }) catch |err| { |
| 218 | diag.report(std.io.getStdErr().writer(), err) catch {}; | 218 | diag.report(std.io.getStdErr().writer(), err) catch {}; |
| @@ -231,11 +231,11 @@ pub fn main() !void { | |||
| 231 | } | 231 | } |
| 232 | 232 | ||
| 233 | fn mathMain(gpa: std.mem.Allocator, iter: *std.process.ArgIterator, main_args: MainArgs) !void { | 233 | fn mathMain(gpa: std.mem.Allocator, iter: *std.process.ArgIterator, main_args: MainArgs) !void { |
| 234 | // The parent arguments are not used it, but there are cases where it might be useful, so | 234 | // The parent arguments are not used here, but there are cases where it might be useful, so |
| 235 | // the example shows how to pass the arguments around. | 235 | // this example shows how to pass the arguments around. |
| 236 | _ = main_args; | 236 | _ = main_args; |
| 237 | 237 | ||
| 238 | // The parameters for the subcommand | 238 | // The parameters for the subcommand. |
| 239 | const params = comptime clap.parseParamsComptime( | 239 | const params = comptime clap.parseParamsComptime( |
| 240 | \\-h, --help Display this help and exit. | 240 | \\-h, --help Display this help and exit. |
| 241 | \\-a, --add Add the two numbers | 241 | \\-a, --add Add the two numbers |
| @@ -245,7 +245,7 @@ fn mathMain(gpa: std.mem.Allocator, iter: *std.process.ArgIterator, main_args: M | |||
| 245 | \\ | 245 | \\ |
| 246 | ); | 246 | ); |
| 247 | 247 | ||
| 248 | // Here we pass the partially parsed argument iterator | 248 | // Here we pass the partially parsed argument iterator. |
| 249 | var diag = clap.Diagnostic{}; | 249 | var diag = clap.Diagnostic{}; |
| 250 | var res = clap.parseEx(clap.Help, ¶ms, clap.parsers.default, iter, .{ | 250 | var res = clap.parseEx(clap.Help, ¶ms, clap.parsers.default, iter, .{ |
| 251 | .diagnostic = &diag, | 251 | .diagnostic = &diag, |
| @@ -297,7 +297,7 @@ pub fn main() !void { | |||
| 297 | var iter = try std.process.ArgIterator.initWithAllocator(allocator); | 297 | var iter = try std.process.ArgIterator.initWithAllocator(allocator); |
| 298 | defer iter.deinit(); | 298 | defer iter.deinit(); |
| 299 | 299 | ||
| 300 | // Skip exe argument | 300 | // Skip exe argument. |
| 301 | _ = iter.next(); | 301 | _ = iter.next(); |
| 302 | 302 | ||
| 303 | // Initialize our diagnostics, which can be used for reporting useful errors. | 303 | // Initialize our diagnostics, which can be used for reporting useful errors. |
| @@ -312,7 +312,7 @@ pub fn main() !void { | |||
| 312 | 312 | ||
| 313 | // Because we use a streaming parser, we have to consume each argument parsed individually. | 313 | // Because we use a streaming parser, we have to consume each argument parsed individually. |
| 314 | while (parser.next() catch |err| { | 314 | while (parser.next() catch |err| { |
| 315 | // Report useful error and exit | 315 | // Report useful error and exit. |
| 316 | diag.report(std.io.getStdErr().writer(), err) catch {}; | 316 | diag.report(std.io.getStdErr().writer(), err) catch {}; |
| 317 | return err; | 317 | return err; |
| 318 | }) |arg| { | 318 | }) |arg| { |
| @@ -335,15 +335,13 @@ const std = @import("std"); | |||
| 335 | 335 | ||
| 336 | ``` | 336 | ``` |
| 337 | 337 | ||
| 338 | Currently, this parser is the only parser that allows an array of `Param` that | 338 | Currently, this parser is the only parser that allows an array of `Param` that is generated at runtime. |
| 339 | is generated at runtime. | ||
| 340 | 339 | ||
| 341 | ### `help` | 340 | ### `help` |
| 342 | 341 | ||
| 343 | The `help` prints a simple list of all parameters the program can take. It expects the | 342 | `help` prints a simple list of all parameters the program can take. It expects the `Id` to have a |
| 344 | `Id` to have a `description` method and an `value` method so that it can provide that | 343 | `description` method and an `value` method so that it can provide that in the output. `HelpOptions` |
| 345 | in the output. `HelpOptions` is passed to `help` to control how the help message is | 344 | is passed to `help` to control how the help message is printed. |
| 346 | printed. | ||
| 347 | 345 | ||
| 348 | ```zig | 346 | ```zig |
| 349 | pub fn main() !void { | 347 | pub fn main() !void { |
| @@ -385,8 +383,8 @@ $ zig-out/bin/help --help | |||
| 385 | 383 | ||
| 386 | ### `usage` | 384 | ### `usage` |
| 387 | 385 | ||
| 388 | The `usage` prints a small abbreviated version of the help message. It expects the `Id` | 386 | `usage` prints a small abbreviated version of the help message. It expects the `Id` to have a |
| 389 | to have a `value` method so it can provide that in the output. | 387 | `value` method so it can provide that in the output. |
| 390 | 388 | ||
| 391 | ```zig | 389 | ```zig |
| 392 | pub fn main() !void { | 390 | pub fn main() !void { |
diff --git a/example/README.md.template b/example/README.md.template index bcd3774..bbf5cb8 100644 --- a/example/README.md.template +++ b/example/README.md.template | |||
| @@ -45,8 +45,8 @@ exe.root_module.addImport("clap", clap.module("clap")); | |||
| 45 | 45 | ||
| 46 | ## API Reference | 46 | ## API Reference |
| 47 | 47 | ||
| 48 | Automatically generated API Reference for the project | 48 | Automatically generated API Reference for the project can be found at https://Hejsil.github.io/ |
| 49 | can be found at https://Hejsil.github.io/zig-clap. | 49 | zig-clap. |
| 50 | Note that Zig autodoc is in beta; the website may be broken or incomplete. | 50 | Note that Zig autodoc is in beta; the website may be broken or incomplete. |
| 51 | 51 | ||
| 52 | ## Examples | 52 | ## Examples |
| @@ -59,16 +59,16 @@ The simplest way to use this library is to just call the `clap.parse` function. | |||
| 59 | {s} | 59 | {s} |
| 60 | ``` | 60 | ``` |
| 61 | 61 | ||
| 62 | The result will contain an `args` field and a `positionals` field. `args` will have one field | 62 | The result will contain an `args` field and a `positionals` field. `args` will have one field for |
| 63 | for each none positional parameter of your program. The name of the field will be the longest | 63 | each non-positional parameter of your program. The name of the field will be the longest name of the |
| 64 | name of the parameter. `positionals` be a tuple with one field for each positional parameter. | 64 | parameter. `positionals` will be a tuple with one field for each positional parameter. |
| 65 | 65 | ||
| 66 | The fields in `args` and `postionals` are typed. The type is based on the name of the value the | 66 | The fields in `args` and `postionals` are typed. The type is based on the name of the value the |
| 67 | parameter takes. Since `--number` takes a `usize` the field `res.args.number` has the type `usize`. | 67 | parameter takes. Since `--number` takes a `usize` the field `res.args.number` has the type `usize`. |
| 68 | 68 | ||
| 69 | Note that this is only the case because `clap.parsers.default` has a field called `usize` which | 69 | Note that this is only the case because `clap.parsers.default` has a field called `usize` which |
| 70 | contains a parser that returns `usize`. You can pass in something other than | 70 | contains a parser that returns `usize`. You can pass in something other than `clap.parsers.default` |
| 71 | `clap.parsers.default` if you want some other mapping. | 71 | if you want some other mapping. |
| 72 | 72 | ||
| 73 | ```zig | 73 | ```zig |
| 74 | {s} | 74 | {s} |
| @@ -92,15 +92,13 @@ The `streaming.Clap` is the base of all the other parsers. It's a streaming pars | |||
| 92 | {s} | 92 | {s} |
| 93 | ``` | 93 | ``` |
| 94 | 94 | ||
| 95 | Currently, this parser is the only parser that allows an array of `Param` that | 95 | Currently, this parser is the only parser that allows an array of `Param` that is generated at runtime. |
| 96 | is generated at runtime. | ||
| 97 | 96 | ||
| 98 | ### `help` | 97 | ### `help` |
| 99 | 98 | ||
| 100 | The `help` prints a simple list of all parameters the program can take. It expects the | 99 | `help` prints a simple list of all parameters the program can take. It expects the `Id` to have a |
| 101 | `Id` to have a `description` method and an `value` method so that it can provide that | 100 | `description` method and an `value` method so that it can provide that in the output. `HelpOptions` |
| 102 | in the output. `HelpOptions` is passed to `help` to control how the help message is | 101 | is passed to `help` to control how the help message is printed. |
| 103 | printed. | ||
| 104 | 102 | ||
| 105 | ```zig | 103 | ```zig |
| 106 | {s} | 104 | {s} |
| @@ -117,8 +115,8 @@ $ zig-out/bin/help --help | |||
| 117 | 115 | ||
| 118 | ### `usage` | 116 | ### `usage` |
| 119 | 117 | ||
| 120 | The `usage` prints a small abbreviated version of the help message. It expects the `Id` | 118 | `usage` prints a small abbreviated version of the help message. It expects the `Id` to have a |
| 121 | to have a `value` method so it can provide that in the output. | 119 | `value` method so it can provide that in the output. |
| 122 | 120 | ||
| 123 | ```zig | 121 | ```zig |
| 124 | {s} | 122 | {s} |
diff --git a/example/simple-ex.zig b/example/simple-ex.zig index 154e486..22f657f 100644 --- a/example/simple-ex.zig +++ b/example/simple-ex.zig | |||
| @@ -3,7 +3,7 @@ pub fn main() !void { | |||
| 3 | defer _ = gpa.deinit(); | 3 | defer _ = gpa.deinit(); |
| 4 | 4 | ||
| 5 | // First we specify what parameters our program can take. | 5 | // First we specify what parameters our program can take. |
| 6 | // We can use `parseParamsComptime` to parse a string into an array of `Param(Help)` | 6 | // We can use `parseParamsComptime` to parse a string into an array of `Param(Help)`. |
| 7 | const params = comptime clap.parseParamsComptime( | 7 | const params = comptime clap.parseParamsComptime( |
| 8 | \\-h, --help Display this help and exit. | 8 | \\-h, --help Display this help and exit. |
| 9 | \\-n, --number <INT> An option parameter, which takes a value. | 9 | \\-n, --number <INT> An option parameter, which takes a value. |
diff --git a/example/simple.zig b/example/simple.zig index 74157a6..2b7bf0a 100644 --- a/example/simple.zig +++ b/example/simple.zig | |||
| @@ -3,7 +3,7 @@ pub fn main() !void { | |||
| 3 | defer _ = gpa.deinit(); | 3 | defer _ = gpa.deinit(); |
| 4 | 4 | ||
| 5 | // First we specify what parameters our program can take. | 5 | // First we specify what parameters our program can take. |
| 6 | // We can use `parseParamsComptime` to parse a string into an array of `Param(Help)` | 6 | // We can use `parseParamsComptime` to parse a string into an array of `Param(Help)`. |
| 7 | const params = comptime clap.parseParamsComptime( | 7 | const params = comptime clap.parseParamsComptime( |
| 8 | \\-h, --help Display this help and exit. | 8 | \\-h, --help Display this help and exit. |
| 9 | \\-n, --number <usize> An option parameter, which takes a value. | 9 | \\-n, --number <usize> An option parameter, which takes a value. |
| @@ -20,7 +20,7 @@ pub fn main() !void { | |||
| 20 | .diagnostic = &diag, | 20 | .diagnostic = &diag, |
| 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 | diag.report(std.io.getStdErr().writer(), err) catch {}; |
| 25 | return err; | 25 | return err; |
| 26 | }; | 26 | }; |
diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig index 2a20bcb..054c401 100644 --- a/example/streaming-clap.zig +++ b/example/streaming-clap.zig | |||
| @@ -18,7 +18,7 @@ pub fn main() !void { | |||
| 18 | var iter = try std.process.ArgIterator.initWithAllocator(allocator); | 18 | var iter = try std.process.ArgIterator.initWithAllocator(allocator); |
| 19 | defer iter.deinit(); | 19 | defer iter.deinit(); |
| 20 | 20 | ||
| 21 | // Skip exe argument | 21 | // Skip exe argument. |
| 22 | _ = iter.next(); | 22 | _ = iter.next(); |
| 23 | 23 | ||
| 24 | // Initialize our diagnostics, which can be used for reporting useful errors. | 24 | // Initialize our diagnostics, which can be used for reporting useful errors. |
| @@ -33,7 +33,7 @@ pub fn main() !void { | |||
| 33 | 33 | ||
| 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 | diag.report(std.io.getStdErr().writer(), err) catch {}; |
| 38 | return err; | 38 | return err; |
| 39 | }) |arg| { | 39 | }) |arg| { |
diff --git a/example/subcommands.zig b/example/subcommands.zig index fcd4fee..8223f31 100644 --- a/example/subcommands.zig +++ b/example/subcommands.zig | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | // These are our subcommands | 1 | // These are our subcommands. |
| 2 | const SubCommands = enum { | 2 | const SubCommands = enum { |
| 3 | help, | 3 | help, |
| 4 | math, | 4 | math, |
| @@ -8,7 +8,7 @@ const main_parsers = .{ | |||
| 8 | .command = clap.parsers.enumeration(SubCommands), | 8 | .command = clap.parsers.enumeration(SubCommands), |
| 9 | }; | 9 | }; |
| 10 | 10 | ||
| 11 | // The parameters for main. Parameters for the subcommands are specified further down | 11 | // The parameters for `main`. Parameters for the subcommands are specified further down. |
| 12 | const main_params = clap.parseParamsComptime( | 12 | const main_params = clap.parseParamsComptime( |
| 13 | \\-h, --help Display this help and exit. | 13 | \\-h, --help Display this help and exit. |
| 14 | \\<command> | 14 | \\<command> |
| @@ -16,7 +16,7 @@ const main_params = clap.parseParamsComptime( | |||
| 16 | ); | 16 | ); |
| 17 | 17 | ||
| 18 | // To pass around arguments returned by clap, `clap.Result` and `clap.ResultEx` can be used to | 18 | // To pass around arguments returned by clap, `clap.Result` and `clap.ResultEx` can be used to |
| 19 | // get the return type of `clap.parse` and `clap.parseEx` | 19 | // get the return type of `clap.parse` and `clap.parseEx`. |
| 20 | const MainArgs = clap.ResultEx(clap.Help, &main_params, main_parsers); | 20 | const MainArgs = clap.ResultEx(clap.Help, &main_params, main_parsers); |
| 21 | 21 | ||
| 22 | pub fn main() !void { | 22 | pub fn main() !void { |
| @@ -38,7 +38,7 @@ pub fn main() !void { | |||
| 38 | // here because parsed positionals are, like slices and arrays, indexed starting at 0). | 38 | // here because parsed positionals are, like slices and arrays, indexed starting at 0). |
| 39 | // | 39 | // |
| 40 | // This will terminate the parsing after parsing the subcommand enum and leave `iter` | 40 | // This will terminate the parsing after parsing the subcommand enum and leave `iter` |
| 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 | diag.report(std.io.getStdErr().writer(), err) catch {}; |
| @@ -57,11 +57,11 @@ pub fn main() !void { | |||
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | fn mathMain(gpa: std.mem.Allocator, iter: *std.process.ArgIterator, main_args: MainArgs) !void { | 59 | fn mathMain(gpa: std.mem.Allocator, iter: *std.process.ArgIterator, main_args: MainArgs) !void { |
| 60 | // The parent arguments are not used it, but there are cases where it might be useful, so | 60 | // The parent arguments are not used here, but there are cases where it might be useful, so |
| 61 | // the example shows how to pass the arguments around. | 61 | // this example shows how to pass the arguments around. |
| 62 | _ = main_args; | 62 | _ = main_args; |
| 63 | 63 | ||
| 64 | // The parameters for the subcommand | 64 | // The parameters for the subcommand. |
| 65 | const params = comptime clap.parseParamsComptime( | 65 | const params = comptime clap.parseParamsComptime( |
| 66 | \\-h, --help Display this help and exit. | 66 | \\-h, --help Display this help and exit. |
| 67 | \\-a, --add Add the two numbers | 67 | \\-a, --add Add the two numbers |
| @@ -71,7 +71,7 @@ fn mathMain(gpa: std.mem.Allocator, iter: *std.process.ArgIterator, main_args: M | |||
| 71 | \\ | 71 | \\ |
| 72 | ); | 72 | ); |
| 73 | 73 | ||
| 74 | // Here we pass the partially parsed argument iterator | 74 | // Here we pass the partially parsed argument iterator. |
| 75 | var diag = clap.Diagnostic{}; | 75 | var diag = clap.Diagnostic{}; |
| 76 | var res = clap.parseEx(clap.Help, ¶ms, clap.parsers.default, iter, .{ | 76 | var res = clap.parseEx(clap.Help, ¶ms, clap.parsers.default, iter, .{ |
| 77 | .diagnostic = &diag, | 77 | .diagnostic = &diag, |