diff options
Diffstat (limited to '')
| -rw-r--r-- | README.md | 42 |
1 files changed, 18 insertions, 24 deletions
| @@ -15,23 +15,21 @@ A simple and easy to use command line argument parser library for Zig. | |||
| 15 | 15 | ||
| 16 | ### `StreamingClap` | 16 | ### `StreamingClap` |
| 17 | 17 | ||
| 18 | The `StreamingClap` is base of all the other parsers. It's a streaming parser that uses an | 18 | The `StreamingClap` is the base of all the other parsers. It's a streaming parser that uses an |
| 19 | `args.Iterator` to provide it with arguments lazily. | 19 | `args.Iterator` to provide it with arguments lazily. |
| 20 | 20 | ||
| 21 | ```rust | 21 | ```rust |
| 22 | const params = []clap.Param(u8){ | 22 | const params = []clap.Param(u8){ |
| 23 | clap.Param(void).flag('h', false, clap.Names.both("help")), | 23 | clap.Param(u8).flag('h', clap.Names.both("help")), |
| 24 | clap.Param(void).option('n', true, clap.Names.both("number")), | 24 | clap.Param(u8).option('n', clap.Names.both("number")), |
| 25 | clap.Param(void).positional('f'), | 25 | clap.Param(u8).positional('f'), |
| 26 | }; | 26 | }; |
| 27 | 27 | ||
| 28 | var os_iter = clap.args.OsIterator.init(allocator); | 28 | var iter = clap.args.OsIterator.init(allocator); |
| 29 | const iter = &os_iter.iter; | 29 | defer iter.deinit(); |
| 30 | defer os_iter.deinit(); | ||
| 31 | |||
| 32 | const exe = try iter.next(); | 30 | const exe = try iter.next(); |
| 33 | 31 | ||
| 34 | var parser = clap.StreamingClap(u8, clap.args.OsIterator.Error).init(params, iter); | 32 | var parser = clap.StreamingClap(u8, clap.args.OsIterator).init(params, &iter); |
| 35 | 33 | ||
| 36 | while (try parser.next()) |arg| { | 34 | while (try parser.next()) |arg| { |
| 37 | switch (arg.param.id) { | 35 | switch (arg.param.id) { |
| @@ -40,7 +38,7 @@ while (try parser.next()) |arg| { | |||
| 40 | 'f' => debug.warn("{}\n", arg.value.?), | 38 | 'f' => debug.warn("{}\n", arg.value.?), |
| 41 | else => unreachable, | 39 | else => unreachable, |
| 42 | } | 40 | } |
| 43 | } | 41 | } |
| 44 | ``` | 42 | ``` |
| 45 | 43 | ||
| 46 | ### `ComptimeClap` | 44 | ### `ComptimeClap` |
| @@ -50,18 +48,16 @@ them available through three functions (`flag`, `option`, `positionals`). | |||
| 50 | 48 | ||
| 51 | ```rust | 49 | ```rust |
| 52 | const params = comptime []clap.Param(void){ | 50 | const params = comptime []clap.Param(void){ |
| 53 | clap.Param(void).flag({}, false, clap.Names.both("help")), | 51 | clap.Param(void).flag({}, clap.Names.both("help")), |
| 54 | clap.Param(void).option({}, true, clap.Names.both("number")), | 52 | clap.Param(void).option({}, clap.Names.both("number")), |
| 55 | clap.Param(void).positional({}), | 53 | clap.Param(void).positional({}), |
| 56 | }; | 54 | }; |
| 57 | 55 | ||
| 58 | var os_iter = clap.args.OsIterator.init(allocator); | 56 | var iter = clap.args.OsIterator.init(allocator); |
| 59 | const iter = &os_iter.iter; | 57 | defer iter.deinit(); |
| 60 | defer os_iter.deinit(); | ||
| 61 | |||
| 62 | const exe = try iter.next(); | 58 | const exe = try iter.next(); |
| 63 | 59 | ||
| 64 | var args = try clap.ComptimeClap(void, params).parse(allocator, clap.args.OsIterator.Error, iter); | 60 | var args = try clap.ComptimeClap(void, params).parse(allocator, clap.args.OsIterator, &iter); |
| 65 | defer args.deinit(); | 61 | defer args.deinit(); |
| 66 | 62 | ||
| 67 | if (args.flag("--help")) | 63 | if (args.flag("--help")) |
| @@ -78,16 +74,14 @@ program can take: | |||
| 78 | 74 | ||
| 79 | ```rust | 75 | ```rust |
| 80 | const params = comptime []clap.Param(void){ | 76 | const params = comptime []clap.Param(void){ |
| 81 | clap.Param(void).init({}, false, clap.Names.both("help")), | 77 | clap.Param(void).flag({}, clap.Names.both("help")), |
| 82 | }; | 78 | }; |
| 83 | 79 | ||
| 84 | var os_iter = clap.args.OsIterator.init(allocator); | 80 | var iter = clap.args.OsIterator.init(allocator); |
| 85 | const iter = &os_iter.iter; | 81 | defer iter.deinit(); |
| 86 | defer os_iter.deinit(); | ||
| 87 | |||
| 88 | const exe = try iter.next(); | 82 | const exe = try iter.next(); |
| 89 | 83 | ||
| 90 | var args = try clap.ComptimeClap(params).parse(allocator, clap.args.OsIterator.Error, iter); | 84 | var args = try clap.ComptimeClap(void, params).parse(allocator, clap.args.OsIterator, &iter); |
| 91 | defer args.deinit(); | 85 | defer args.deinit(); |
| 92 | 86 | ||
| 93 | if (args.flag("--helps")) | 87 | if (args.flag("--helps")) |
| @@ -106,7 +100,7 @@ zig-clap/example/comptime-clap.zig:41:18: note: called from here | |||
| 106 | ^ | 100 | ^ |
| 107 | ``` | 101 | ``` |
| 108 | 102 | ||
| 109 | Ofc, this limits you to use only parameters that are comptime known. | 103 | Ofc, this limits you to parameters that are comptime known. |
| 110 | 104 | ||
| 111 | ### `help` | 105 | ### `help` |
| 112 | 106 | ||