Adds demo.
This commit is contained in:
parent
1d1179ee9e
commit
94c96afcdd
25
README.md
25
README.md
|
@ -1,2 +1,27 @@
|
|||
# zig-args
|
||||
Simple-to-use argument parser with struct-based config
|
||||
|
||||
```zig
|
||||
const options = try argsParser.parse(struct {
|
||||
// This declares long options for double hyphen
|
||||
output: ?[]const u8 = null,
|
||||
@"with-offset": bool = false,
|
||||
@"with-hexdump": bool = false,
|
||||
@"intermix-source": bool = false,
|
||||
numberOfBytes: ?i32 = null,
|
||||
|
||||
// This declares short-hand options for single hyphen
|
||||
pub const shorthands = .{
|
||||
.S = "intermix-source",
|
||||
.b = "with-hexdump",
|
||||
.O = "with-offset",
|
||||
.o = "output",
|
||||
};
|
||||
}, &args, argsAllocator);
|
||||
defer options.deinit();
|
||||
|
||||
std.debug.warn("parsed result:\n{}\npositionals:\n", .{options.options});
|
||||
for (options.args) |arg| {
|
||||
std.debug.warn("\t{}\n", .{arg});
|
||||
}
|
||||
```
|
2
demo.zig
2
demo.zig
|
@ -13,12 +13,14 @@ pub fn main() !void {
|
|||
defer argsAllocator.free(exeName);
|
||||
|
||||
const options = try argsParser.parse(struct {
|
||||
// This declares long options for double hyphen
|
||||
output: ?[]const u8 = null,
|
||||
@"with-offset": bool = false,
|
||||
@"with-hexdump": bool = false,
|
||||
@"intermix-source": bool = false,
|
||||
numberOfBytes: ?i32 = null,
|
||||
|
||||
// This declares short-hand options for single hyphen
|
||||
pub const shorthands = .{
|
||||
.S = "intermix-source",
|
||||
.b = "with-hexdump",
|
||||
|
|
Loading…
Reference in New Issue
Block a user