summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md12
-rw-r--r--example/comptime-clap.zig6
-rw-r--r--example/streaming-clap.zig6
-rw-r--r--src/comptime.zig8
-rw-r--r--src/index.zig22
-rw-r--r--src/streaming.zig22
6 files changed, 40 insertions, 36 deletions
diff --git a/README.md b/README.md
index 92f53c2..68970d9 100644
--- a/README.md
+++ b/README.md
@@ -20,9 +20,9 @@ The `StreamingClap` is base of all the other parsers. It's a streaming parser th
20 20
21```rust 21```rust
22const params = []clap.Param(u8){ 22const params = []clap.Param(u8){
23 clap.Param(u8).init('h', false, clap.Names.prefix("help")), 23 clap.Param(void).flag('h', false, clap.Names.prefix("help")),
24 clap.Param(u8).init('n', true, clap.Names.prefix("number")), 24 clap.Param(void).option('n', true, clap.Names.prefix("number")),
25 clap.Param(u8).init('f', true, clap.Names.positional()), 25 clap.Param(void).positional('f'),
26}; 26};
27 27
28var os_iter = clap.args.OsIterator.init(allocator); 28var os_iter = clap.args.OsIterator.init(allocator);
@@ -50,9 +50,9 @@ them available through three functions (`flag`, `option`, `positionals`).
50 50
51```rust 51```rust
52const params = comptime []clap.Param(void){ 52const params = comptime []clap.Param(void){
53 clap.Param(void).init({}, false, clap.Names.prefix("help")), 53 clap.Param(void).flag({}, false, clap.Names.prefix("help")),
54 clap.Param(void).init({}, true, clap.Names.prefix("number")), 54 clap.Param(void).option({}, true, clap.Names.prefix("number")),
55 clap.Param(void).init({}, true, clap.Names.positional()), 55 clap.Param(void).positional({}),
56}; 56};
57 57
58var os_iter = clap.args.OsIterator.init(allocator); 58var os_iter = clap.args.OsIterator.init(allocator);
diff --git a/example/comptime-clap.zig b/example/comptime-clap.zig
index e44d9b1..3b7b42b 100644
--- a/example/comptime-clap.zig
+++ b/example/comptime-clap.zig
@@ -17,12 +17,12 @@ pub fn main() !void {
17 // * A "Names" struct, which determins what names the parameter will have on the 17 // * A "Names" struct, which determins what names the parameter will have on the
18 // commandline. Names.prefix inits a "Names" struct that has the "short" name 18 // commandline. Names.prefix inits a "Names" struct that has the "short" name
19 // set to the first letter, and the "long" name set to the full name. 19 // set to the first letter, and the "long" name set to the full name.
20 clap.Param(void).init({}, false, clap.Names.prefix("help")), 20 clap.Param(void).flag({}, clap.Names.prefix("help")),
21 clap.Param(void).init({}, true, clap.Names.prefix("number")), 21 clap.Param(void).option({}, clap.Names.prefix("number")),
22 22
23 // Names.positional returns a "Names" struct where neither the "short" or "long" 23 // Names.positional returns a "Names" struct where neither the "short" or "long"
24 // name is set. 24 // name is set.
25 clap.Param(void).init({}, true, clap.Names.positional()), 25 clap.Param(void).positional({}),
26 }; 26 };
27 27
28 // We then initialize an argument iterator. We will use the OsIterator as it nicely 28 // We then initialize an argument iterator. We will use the OsIterator as it nicely
diff --git a/example/streaming-clap.zig b/example/streaming-clap.zig
index 0dc2bf7..013c1d4 100644
--- a/example/streaming-clap.zig
+++ b/example/streaming-clap.zig
@@ -17,12 +17,12 @@ pub fn main() !void {
17 // * A "Names" struct, which determins what names the parameter will have on the 17 // * A "Names" struct, which determins what names the parameter will have on the
18 // commandline. Names.prefix inits a "Names" struct that has the "short" name 18 // commandline. Names.prefix inits a "Names" struct that has the "short" name
19 // set to the first letter, and the "long" name set to the full name. 19 // set to the first letter, and the "long" name set to the full name.
20 clap.Param(u8).init('h', false, clap.Names.prefix("help")), 20 clap.Param(u8).flag('h', clap.Names.prefix("help")),
21 clap.Param(u8).init('n', true, clap.Names.prefix("number")), 21 clap.Param(u8).option('n', clap.Names.prefix("number")),
22 22
23 // Names.positional returns a "Names" struct where neither the "short" or "long" 23 // Names.positional returns a "Names" struct where neither the "short" or "long"
24 // name is set. 24 // name is set.
25 clap.Param(u8).init('f', true, clap.Names.positional()), 25 clap.Param(u8).positional('f'),
26 }; 26 };
27 27
28 // We then initialize an argument iterator. We will use the OsIterator as it nicely 28 // We then initialize an argument iterator. We will use the OsIterator as it nicely
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];