diff options
| author | 2018-11-14 14:25:42 +0100 | |
|---|---|---|
| committer | 2018-11-14 14:25:42 +0100 | |
| commit | f968d56d96989d1c74664449f509d7d1b2e3010f (patch) | |
| tree | 0b9f51b379af7a80b578d7e0459b680fb926bf0f /src/index.zig | |
| parent | Restructured and make StreamingClap simpler (diff) | |
| download | zig-clap-f968d56d96989d1c74664449f509d7d1b2e3010f.tar.gz zig-clap-f968d56d96989d1c74664449f509d7d1b2e3010f.tar.xz zig-clap-f968d56d96989d1c74664449f509d7d1b2e3010f.zip | |
Added pub flag/option/positional init funcs to Param
Diffstat (limited to 'src/index.zig')
| -rw-r--r-- | src/index.zig | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/index.zig b/src/index.zig index dde4748..5900424 100644 --- a/src/index.zig +++ b/src/index.zig | |||
| @@ -23,14 +23,6 @@ pub const Names = struct { | |||
| 23 | /// '--' prefix | 23 | /// '--' prefix |
| 24 | long: ?[]const u8, | 24 | long: ?[]const u8, |
| 25 | 25 | ||
| 26 | /// Initializes no names | ||
| 27 | pub fn positional() Names { | ||
| 28 | return Names{ | ||
| 29 | .short = null, | ||
| 30 | .long = null, | ||
| 31 | }; | ||
| 32 | } | ||
| 33 | |||
| 34 | /// Initializes a short name | 26 | /// Initializes a short name |
| 35 | pub fn short(s: u8) Names { | 27 | pub fn short(s: u8) Names { |
| 36 | return Names{ | 28 | return Names{ |
| @@ -87,7 +79,19 @@ pub fn Param(comptime Id: type) type { | |||
| 87 | takes_value: bool, | 79 | takes_value: bool, |
| 88 | names: Names, | 80 | names: Names, |
| 89 | 81 | ||
| 90 | pub fn init(id: Id, takes_value: bool, names: Names) @This() { | 82 | pub fn flag(id: Id, names: Names) @This() { |
| 83 | return init(id, false, names); | ||
| 84 | } | ||
| 85 | |||
| 86 | pub fn option(id: Id, names: Names) @This() { | ||
| 87 | return init(id, true, names); | ||
| 88 | } | ||
| 89 | |||
| 90 | pub fn positional(id: Id) @This() { | ||
| 91 | return init(id, true, Names{ .short = null, .long = null }); | ||
| 92 | } | ||
| 93 | |||
| 94 | fn init(id: Id, takes_value: bool, names: Names) @This() { | ||
| 91 | // Assert, that if the param have no name, then it has to take | 95 | // Assert, that if the param have no name, then it has to take |
| 92 | // a value. | 96 | // a value. |
| 93 | debug.assert( | 97 | debug.assert( |