summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/comptime.zig8
-rw-r--r--src/index.zig22
-rw-r--r--src/streaming.zig22
3 files changed, 28 insertions, 24 deletions
diff --git a/src/comptime.zig b/src/comptime.zig
index b11dccc..ddcd7e1 100644
--- a/src/comptime.zig
+++ b/src/comptime.zig
@@ -108,19 +108,19 @@ pub fn ComptimeClap(comptime Id: type, comptime params: []const clap.Param(Id))
108 108
109test "clap.comptime.ComptimeClap" { 109test "clap.comptime.ComptimeClap" {
110 const Clap = ComptimeClap(void, comptime []clap.Param(void){ 110 const Clap = ComptimeClap(void, comptime []clap.Param(void){
111 clap.Param(void).init({}, false, clap.Names{ 111 clap.Param(void).flag({}, clap.Names{
112 .short = 'a', 112 .short = 'a',
113 .long = "aa", 113 .long = "aa",
114 }), 114 }),
115 clap.Param(void).init({}, false, clap.Names{ 115 clap.Param(void).flag({}, clap.Names{
116 .short = 'b', 116 .short = 'b',
117 .long = "bb", 117 .long = "bb",
118 }), 118 }),
119 clap.Param(void).init({}, true, clap.Names{ 119 clap.Param(void).option({}, clap.Names{
120 .short = 'c', 120 .short = 'c',
121 .long = "cc", 121 .long = "cc",
122 }), 122 }),
123 clap.Param(void).init({}, true, clap.Names.positional()), 123 clap.Param(void).positional({}),
124 }); 124 });
125 125
126 var buf: [1024]u8 = undefined; 126 var buf: [1024]u8 = undefined;
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(
diff --git a/src/streaming.zig b/src/streaming.zig
index bfb4045..99eaecb 100644
--- a/src/streaming.zig
+++ b/src/streaming.zig
@@ -212,9 +212,9 @@ fn testNoErr(params: []const clap.Param(u8), args_strings: []const []const u8, r
212 212
213test "clap.streaming.StreamingClap: short params" { 213test "clap.streaming.StreamingClap: short params" {
214 const params = []clap.Param(u8){ 214 const params = []clap.Param(u8){
215 clap.Param(u8).init(0, false, clap.Names.short('a')), 215 clap.Param(u8).flag(0, clap.Names.short('a')),
216 clap.Param(u8).init(1, false, clap.Names.short('b')), 216 clap.Param(u8).flag(1, clap.Names.short('b')),
217 clap.Param(u8).init(2, true, clap.Names.short('c')), 217 clap.Param(u8).option(2, clap.Names.short('c')),
218 }; 218 };
219 219
220 const a = &params[0]; 220 const a = &params[0];
@@ -247,9 +247,9 @@ test "clap.streaming.StreamingClap: short params" {
247 247
248test "clap.streaming.StreamingClap: long params" { 248test "clap.streaming.StreamingClap: long params" {
249 const params = []clap.Param(u8){ 249 const params = []clap.Param(u8){
250 clap.Param(u8).init(0, false, clap.Names.long("aa")), 250 clap.Param(u8).flag(0, clap.Names.long("aa")),
251 clap.Param(u8).init(1, false, clap.Names.long("bb")), 251 clap.Param(u8).flag(1, clap.Names.long("bb")),
252 clap.Param(u8).init(2, true, clap.Names.long("cc")), 252 clap.Param(u8).option(2, clap.Names.long("cc")),
253 }; 253 };
254 254
255 const aa = &params[0]; 255 const aa = &params[0];
@@ -273,7 +273,7 @@ test "clap.streaming.StreamingClap: long params" {
273} 273}
274 274
275test "clap.streaming.StreamingClap: positional params" { 275test "clap.streaming.StreamingClap: positional params" {
276 const params = []clap.Param(u8){clap.Param(u8).init(0, true, clap.Names.positional())}; 276 const params = []clap.Param(u8){clap.Param(u8).positional(0)};
277 277
278 testNoErr( 278 testNoErr(
279 params, 279 params,
@@ -287,19 +287,19 @@ test "clap.streaming.StreamingClap: positional params" {
287 287
288test "clap.streaming.StreamingClap: all params" { 288test "clap.streaming.StreamingClap: all params" {
289 const params = []clap.Param(u8){ 289 const params = []clap.Param(u8){
290 clap.Param(u8).init(0, false, clap.Names{ 290 clap.Param(u8).flag(0, clap.Names{
291 .short = 'a', 291 .short = 'a',
292 .long = "aa", 292 .long = "aa",
293 }), 293 }),
294 clap.Param(u8).init(1, false, clap.Names{ 294 clap.Param(u8).flag(1, clap.Names{
295 .short = 'b', 295 .short = 'b',
296 .long = "bb", 296 .long = "bb",
297 }), 297 }),
298 clap.Param(u8).init(2, true, clap.Names{ 298 clap.Param(u8).option(2, clap.Names{
299 .short = 'c', 299 .short = 'c',
300 .long = "cc", 300 .long = "cc",
301 }), 301 }),
302 clap.Param(u8).init(3, true, clap.Names.positional()), 302 clap.Param(u8).positional(3),
303 }; 303 };
304 304
305 const aa = &params[0]; 305 const aa = &params[0];