2020-03-05 05:37:11 +08:00
|
|
|
const std = @import("std");
|
2020-03-05 05:58:12 +08:00
|
|
|
const argsParser = @import("args.zig");
|
2020-03-05 05:37:11 +08:00
|
|
|
|
|
|
|
pub fn main() !void {
|
2020-05-17 09:46:42 +08:00
|
|
|
var argsAllocator = std.heap.page_allocator;
|
2020-03-05 05:37:11 +08:00
|
|
|
|
2020-03-05 21:31:35 +08:00
|
|
|
const options = try argsParser.parseForCurrentProcess(struct {
|
2020-03-05 05:38:26 +08:00
|
|
|
// This declares long options for double hyphen
|
2020-03-05 05:37:11 +08:00
|
|
|
output: ?[]const u8 = null,
|
|
|
|
@"with-offset": bool = false,
|
|
|
|
@"with-hexdump": bool = false,
|
|
|
|
@"intermix-source": bool = false,
|
|
|
|
numberOfBytes: ?i32 = null,
|
2020-11-15 10:11:56 +08:00
|
|
|
signed_number: ?i64 = null,
|
|
|
|
unsigned_number: ?u64 = null,
|
2020-03-05 21:13:14 +08:00
|
|
|
mode: enum { default, special, slow, fast } = .default,
|
2020-03-05 05:37:11 +08:00
|
|
|
|
2020-03-05 05:38:26 +08:00
|
|
|
// This declares short-hand options for single hyphen
|
2020-03-05 05:37:11 +08:00
|
|
|
pub const shorthands = .{
|
|
|
|
.S = "intermix-source",
|
|
|
|
.b = "with-hexdump",
|
|
|
|
.O = "with-offset",
|
|
|
|
.o = "output",
|
|
|
|
};
|
2020-03-05 21:31:35 +08:00
|
|
|
}, argsAllocator);
|
2020-03-05 05:37:11 +08:00
|
|
|
defer options.deinit();
|
|
|
|
|
2021-01-04 18:37:36 +08:00
|
|
|
std.debug.print("executable name: {s}\n", .{options.executable_name});
|
2020-03-05 21:31:35 +08:00
|
|
|
|
2020-06-26 17:27:17 +08:00
|
|
|
std.debug.print("parsed options:\n", .{});
|
2020-03-05 21:31:35 +08:00
|
|
|
inline for (std.meta.fields(@TypeOf(options.options))) |fld| {
|
2021-01-04 18:37:36 +08:00
|
|
|
std.debug.print("\t{s} = {}\n", .{
|
2020-03-05 21:31:35 +08:00
|
|
|
fld.name,
|
|
|
|
@field(options.options, fld.name),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-06-26 17:27:17 +08:00
|
|
|
std.debug.print("parsed positionals:\n", .{});
|
2020-03-05 21:31:35 +08:00
|
|
|
for (options.positionals) |arg| {
|
2021-01-04 18:37:36 +08:00
|
|
|
std.debug.print("\t'{s}'\n", .{arg});
|
2020-03-05 05:37:11 +08:00
|
|
|
}
|
|
|
|
}
|