diff options
| author | 2023-12-13 08:53:06 +0100 | |
|---|---|---|
| committer | 2023-12-13 08:53:06 +0100 | |
| commit | feffdff4094ea3927eb3880b46b65e700f1e86fb (patch) | |
| tree | 071a86610548ebed5b8bec0617cf79cbeeee65fd /README.md | |
| parent | Fix short only params not getting fields in `Arguments` (diff) | |
| download | zig-clap-no-default-allocator.tar.gz zig-clap-no-default-allocator.tar.xz zig-clap-no-default-allocator.zip | |
Remove the default allocator from `ParseOptions`no-default-allocator
fixes #111
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 22 |
1 files changed, 20 insertions, 2 deletions
| @@ -37,6 +37,9 @@ const debug = std.debug; | |||
| 37 | const io = std.io; | 37 | const io = std.io; |
| 38 | 38 | ||
| 39 | pub fn main() !void { | 39 | pub fn main() !void { |
| 40 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | ||
| 41 | defer _ = gpa.deinit(); | ||
| 42 | |||
| 40 | // First we specify what parameters our program can take. | 43 | // First we specify what parameters our program can take. |
| 41 | // We can use `parseParamsComptime` to parse a string into an array of `Param(Help)` | 44 | // We can use `parseParamsComptime` to parse a string into an array of `Param(Help)` |
| 42 | const params = comptime clap.parseParamsComptime( | 45 | const params = comptime clap.parseParamsComptime( |
| @@ -53,6 +56,7 @@ pub fn main() !void { | |||
| 53 | var diag = clap.Diagnostic{}; | 56 | var diag = clap.Diagnostic{}; |
| 54 | var res = clap.parse(clap.Help, ¶ms, clap.parsers.default, .{ | 57 | var res = clap.parse(clap.Help, ¶ms, clap.parsers.default, .{ |
| 55 | .diagnostic = &diag, | 58 | .diagnostic = &diag, |
| 59 | .allocator = gpa.allocator(), | ||
| 56 | }) catch |err| { | 60 | }) catch |err| { |
| 57 | // Report useful error and exit | 61 | // Report useful error and exit |
| 58 | diag.report(io.getStdErr().writer(), err) catch {}; | 62 | diag.report(io.getStdErr().writer(), err) catch {}; |
| @@ -92,6 +96,9 @@ const io = std.io; | |||
| 92 | const process = std.process; | 96 | const process = std.process; |
| 93 | 97 | ||
| 94 | pub fn main() !void { | 98 | pub fn main() !void { |
| 99 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | ||
| 100 | defer _ = gpa.deinit(); | ||
| 101 | |||
| 95 | // First we specify what parameters our program can take. | 102 | // First we specify what parameters our program can take. |
| 96 | // We can use `parseParamsComptime` to parse a string into an array of `Param(Help)` | 103 | // We can use `parseParamsComptime` to parse a string into an array of `Param(Help)` |
| 97 | const params = comptime clap.parseParamsComptime( | 104 | const params = comptime clap.parseParamsComptime( |
| @@ -116,6 +123,7 @@ pub fn main() !void { | |||
| 116 | var diag = clap.Diagnostic{}; | 123 | var diag = clap.Diagnostic{}; |
| 117 | var res = clap.parse(clap.Help, ¶ms, parsers, .{ | 124 | var res = clap.parse(clap.Help, ¶ms, parsers, .{ |
| 118 | .diagnostic = &diag, | 125 | .diagnostic = &diag, |
| 126 | .allocator = gpa.allocator(), | ||
| 119 | }) catch |err| { | 127 | }) catch |err| { |
| 120 | diag.report(io.getStdErr().writer(), err) catch {}; | 128 | diag.report(io.getStdErr().writer(), err) catch {}; |
| 121 | return err; | 129 | return err; |
| @@ -219,13 +227,18 @@ const clap = @import("clap"); | |||
| 219 | const std = @import("std"); | 227 | const std = @import("std"); |
| 220 | 228 | ||
| 221 | pub fn main() !void { | 229 | pub fn main() !void { |
| 230 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | ||
| 231 | defer _ = gpa.deinit(); | ||
| 232 | |||
| 222 | const params = comptime clap.parseParamsComptime( | 233 | const params = comptime clap.parseParamsComptime( |
| 223 | \\-h, --help Display this help and exit. | 234 | \\-h, --help Display this help and exit. |
| 224 | \\-v, --version Output version information and exit. | 235 | \\-v, --version Output version information and exit. |
| 225 | \\ | 236 | \\ |
| 226 | ); | 237 | ); |
| 227 | 238 | ||
| 228 | var res = try clap.parse(clap.Help, ¶ms, clap.parsers.default, .{}); | 239 | var res = try clap.parse(clap.Help, ¶ms, clap.parsers.default, .{ |
| 240 | .allocator = gpa.allocator(), | ||
| 241 | }); | ||
| 229 | defer res.deinit(); | 242 | defer res.deinit(); |
| 230 | 243 | ||
| 231 | // `clap.help` is a function that can print a simple help message. It can print any `Param` | 244 | // `clap.help` is a function that can print a simple help message. It can print any `Param` |
| @@ -257,6 +270,9 @@ const clap = @import("clap"); | |||
| 257 | const std = @import("std"); | 270 | const std = @import("std"); |
| 258 | 271 | ||
| 259 | pub fn main() !void { | 272 | pub fn main() !void { |
| 273 | var gpa = std.heap.GeneralPurposeAllocator(.{}){}; | ||
| 274 | defer _ = gpa.deinit(); | ||
| 275 | |||
| 260 | const params = comptime clap.parseParamsComptime( | 276 | const params = comptime clap.parseParamsComptime( |
| 261 | \\-h, --help Display this help and exit. | 277 | \\-h, --help Display this help and exit. |
| 262 | \\-v, --version Output version information and exit. | 278 | \\-v, --version Output version information and exit. |
| @@ -264,7 +280,9 @@ pub fn main() !void { | |||
| 264 | \\ | 280 | \\ |
| 265 | ); | 281 | ); |
| 266 | 282 | ||
| 267 | var res = try clap.parse(clap.Help, ¶ms, clap.parsers.default, .{}); | 283 | var res = try clap.parse(clap.Help, ¶ms, clap.parsers.default, .{ |
| 284 | .allocator = gpa.allocator(), | ||
| 285 | }); | ||
| 268 | defer res.deinit(); | 286 | defer res.deinit(); |
| 269 | 287 | ||
| 270 | // `clap.usage` is a function that can print a simple help message. It can print any `Param` | 288 | // `clap.usage` is a function that can print a simple help message. It can print any `Param` |