| ... | @@ -112,7 +112,7 @@ pub const Error = error{ | ... | @@ -112,7 +112,7 @@ pub const Error = error{ |
| 112 | /// If `options.prog` is `null`, then the final path component of `argv[0]` is used by default. | 112 | /// If `options.prog` is `null`, then the final path component of `argv[0]` is used by default. |
| 113 | /// | 113 | /// |
| 114 | /// If a parsing/validation error occurs or the `--help` arg is given, | 114 | /// If a parsing/validation error occurs or the `--help` arg is given, |
| 115 | /// this function calls `std.process.exit` with an error status unless `options.exit` is set to `false`, | 115 | /// this function calls `std.process.exit` with `1` and `0` respectively unless `options.exit` is set to `false`, |
| 116 | /// in which case parsing/validation errors return `error.Usage` and `--help` returns `error.Help`. | 116 | /// in which case parsing/validation errors return `error.Usage` and `--help` returns `error.Help`. |
| 117 | /// Allocator errors are always returned from the function. | 117 | /// Allocator errors are always returned from the function. |
| 118 | /// | 118 | /// |
| ... | @@ -165,7 +165,7 @@ test parse { | ... | @@ -165,7 +165,7 @@ test parse { |
| 165 | /// | 165 | /// |
| 166 | /// If a parsing/validation error occurs or the `--help` arg is given, | 166 | /// If a parsing/validation error occurs or the `--help` arg is given, |
| 167 | /// this function returns `error.Usage` or `error.Help` respectively, | 167 | /// this function returns `error.Usage` or `error.Help` respectively, |
| 168 | /// unless `options.exit` is set to `true`, in which case `std.process.exit` is called with an error status instead. | 168 | /// unless `options.exit` is set to `true`, in which case `std.process.exit` is called with `1` or `0` respectively. |
| 169 | /// Allocator errors are always returned from the function. | 169 | /// Allocator errors are always returned from the function. |
| 170 | /// | 170 | /// |
| 171 | /// An `ArenaAllocator` is recommended to cleanup the memory allocated from this function; | 171 | /// An `ArenaAllocator` is recommended to cleanup the memory allocated from this function; |
| ... | @@ -187,7 +187,7 @@ pub fn parseIter(comptime Args: type, arena: Allocator, iter: anytype, options: | ... | @@ -187,7 +187,7 @@ pub fn parseIter(comptime Args: type, arena: Allocator, iter: anytype, options: |
| 187 | /// | 187 | /// |
| 188 | /// If a parsing/validation error occurs or the `--help` arg is given, | 188 | /// If a parsing/validation error occurs or the `--help` arg is given, |
| 189 | /// this function returns `error.Usage` or `error.Help` respectively, | 189 | /// this function returns `error.Usage` or `error.Help` respectively, |
| 190 | /// unless `options.exit` is set to `true`, in which case `std.process.exit` is called with an error status instead. | 190 | /// unless `options.exit` is set to `true`, in which case `std.process.exit` is called with `1` or `0` respectively. |
| 191 | /// Allocator errors are always returned from the function. | 191 | /// Allocator errors are always returned from the function. |
| 192 | /// | 192 | /// |
| 193 | /// An `ArenaAllocator` is recommended to cleanup the memory allocated from this function; | 193 | /// An `ArenaAllocator` is recommended to cleanup the memory allocated from this function; |
| ... | @@ -296,7 +296,7 @@ fn innerParse(comptime Args: type, allocator: Allocator, iter: anytype, prog: [] | ... | @@ -296,7 +296,7 @@ fn innerParse(comptime Args: type, allocator: Allocator, iter: anytype, prog: [] |
| 296 | printGeneratedHelp(writer, prog, named_info); | 296 | printGeneratedHelp(writer, prog, named_info); |
| 297 | } | 297 | } |
| 298 | if (exit_on_error) { | 298 | if (exit_on_error) { |
| 299 | std.process.exit(1); | 299 | std.process.exit(0); |
| 300 | } | 300 | } |
| 301 | return error.Help; | 301 | return error.Help; |
| 302 | } | 302 | } |
| ... | @@ -437,7 +437,7 @@ fn checkArgsType(comptime Args: type) void { | ... | @@ -437,7 +437,7 @@ fn checkArgsType(comptime Args: type) void { |
| 437 | | 437 | |
| 438 | inline for (@typeInfo(args_fields[0].type).@"struct".fields) |field| { | 438 | inline for (@typeInfo(args_fields[0].type).@"struct".fields) |field| { |
| 439 | if (field.is_comptime) @compileError("comptime fields are not supported: " ++ field.name); | 439 | if (field.is_comptime) @compileError("comptime fields are not supported: " ++ field.name); |
| 440 | if (comptime mem.eql(u8, field.name, "help")) @compileError("A field named help is not allowed. to provide custom help formatting, give options.writer and handle error.Help"); | 440 | if (comptime mem.eql(u8, field.name, "help")) @compileError("A field named help is not allowed. add a `pub const help = \"...\";` to your `Args` to provide a custom help string."); |
| 441 | if (comptime mem.startsWith(u8, field.name, "no-")) @compileError("Field name starts with @\"no-\": " ++ field.name ++ ". Note: use a bool type field, and --<name> and --no-<name> will turn it on and off."); | 441 | if (comptime mem.startsWith(u8, field.name, "no-")) @compileError("Field name starts with @\"no-\": " ++ field.name ++ ". Note: use a bool type field, and --<name> and --no-<name> will turn it on and off."); |
| 442 | if (comptime mem.indexOfScalar(u8, field.name, '=') != null) @compileError("Field name contains @\"=\": " ++ field.name); | 442 | if (comptime mem.indexOfScalar(u8, field.name, '=') != null) @compileError("Field name contains @\"=\": " ++ field.name); |
| 443 | | 443 | |
| ... | @@ -502,10 +502,10 @@ test @"error" { | ... | @@ -502,10 +502,10 @@ test @"error" { |
| 502 | const args = try parseSlice(Args, arena.allocator(), &[_][]const u8{ "--output=o.txt", "i.txt" }, .{}); | 502 | const args = try parseSlice(Args, arena.allocator(), &[_][]const u8{ "--output=o.txt", "i.txt" }, .{}); |
| 503 | | 503 | |
| 504 | if (std.fs.path.isAbsolute(args.named.output)) { | 504 | if (std.fs.path.isAbsolute(args.named.output)) { |
| 505 | return std.cli.@"error"("--output must not be absolute: {s}", .{args.named.output}, .{ .exit_on_error = false }); | 505 | return std.cli.@"error"("--output must not be absolute: {s}", .{args.named.output}, .{ .exit = false }); |
| 506 | } | 506 | } |
| 507 | if (args.positional.len > 1) { | 507 | if (args.positional.len > 1) { |
| 508 | return std.cli.@"error"("expected exactly 1 positional arg", .{}, .{ .exit_on_error = false }); | 508 | return std.cli.@"error"("expected exactly 1 positional arg", .{}, .{ .exit = false }); |
| 509 | } | 509 | } |
| 510 | } | 510 | } |
| 511 | | 511 | |
| ... | @@ -633,7 +633,7 @@ inline fn quoteIfEmpty(comptime s: []const u8) []const u8 { | ... | @@ -633,7 +633,7 @@ inline fn quoteIfEmpty(comptime s: []const u8) []const u8 { |
| 633 | } | 633 | } |
| 634 | | 634 | |
| 635 | var failing_writer: Writer = .failing; | 635 | var failing_writer: Writer = .failing; |
| 636 | const silent_options = Options{ .writer = &failing_writer }; | 636 | const silent_options = Options{ .writer = &failing_writer, .exit = false }; |
| 637 | | 637 | |
| 638 | test "usage errors" { | 638 | test "usage errors" { |
| 639 | var arena: std.heap.ArenaAllocator = .init(testing.allocator); | 639 | var arena: std.heap.ArenaAllocator = .init(testing.allocator); |