Skip to content

Commit 8d1fe6d

Browse files
committed
Implemented Nullable Prefixes for Options
- Changed the short and long prefixes in `Option.Config` to be nullable, allowing only one to be specified if desired. - Closes #24
1 parent 5164ddf commit 8d1fe6d

File tree

9 files changed

+709
-699
lines changed

9 files changed

+709
-699
lines changed

docs/data-astNodes.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/data-decls.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/data-exprs.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/data-types.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/src/cova/Option.zig.html

+121-120
Large diffs are not rendered by default.

docs/src/cova/cova.zig.html

+450-448
Large diffs are not rendered by default.

examples/covademo.zig

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const ex_structs = @import("example_structs.zig");
2020
pub const CommandT = Command.Custom(.{
2121
.global_help_prefix = "CovaDemo",
2222
.vals_mandatory = false,
23+
.opt_config = .{
24+
.short_prefix = null,
25+
.long_prefix = "-",
26+
},
2327
});
2428
pub const ValueT = CommandT.ValueT;
2529

src/Option.zig

+9-8
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ pub const Config = struct {
3232
/// Format for the Usage message.
3333
///
3434
/// Must support the following format types in this order:
35-
/// 1. Character (Short Prefix)
36-
/// 2. Optional Character "{?c} (Short Name)
35+
/// 1. Optional Character (Short Prefix)
36+
/// 2. Optional Character "{?c}" (Short Name)
3737
/// 3. String (Long Prefix)
3838
/// 4. Optional String "{?s}" (Long Name)
3939
/// 5. String (Value Name)
4040
/// 6. String (Value Type)
4141
usage_fmt: []const u8 = "[{c}{?c},{s}{?s} \"{s} ({s})\"]",
4242

4343
/// Prefix for Short Options.
44-
short_prefix: u8 = '-',
44+
short_prefix: ?u8 = '-',
4545
/// Prefix for Long Options.
46-
long_prefix: []const u8 = "--",
46+
long_prefix: ?[]const u8 = "--",
4747

4848
/// During parsing, allow there to be no space ' ' between Options and Values.
4949
/// This is allowed per the POSIX standard, but may not be ideal as it interrupts the parsing of chained booleans even in the event of a misstype.
@@ -62,6 +62,7 @@ pub fn Base() type { return Custom(.{}); }
6262

6363
/// Create a Custom Option type from the provided Config (`config`).
6464
pub fn Custom(comptime config: Config) type {
65+
if (config.short_prefix == null and config.long_prefix == null) @compileError("Either a Short or Long prefix must be set for Option Types!");
6566
return struct {
6667
/// The Custom Value type used by this Custom Option type.
6768
const ValueT = Value.Custom(config.val_config);
@@ -121,10 +122,10 @@ pub fn Custom(comptime config: Config) type {
121122
/// Creates the Usage message for this Option and Writes it to the provided Writer (`writer`).
122123
pub fn usage(self: *const @This(), writer: anytype) !void {
123124
try writer.print(usage_fmt, .{
124-
short_prefix,
125-
self.short_name,
126-
long_prefix,
127-
self.long_name,
125+
short_prefix orelse 0,
126+
if (short_prefix != null) self.short_name else 0,
127+
long_prefix orelse "",
128+
if (long_prefix != null) self.long_name else "",
128129
self.val.name(),
129130
self.val.valType(),
130131
});

src/cova.zig

+121-119
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)