Simple-to-use argument parser with struct-based config
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dweiller cce1b89877 Update for deprecation of 1 month ago
.github/workflows First step towards integrated verb parsing. 2 years ago
.gitattributes adds gitattributes. 3 years ago
.gitignore Update to latest master. 2 years ago
LICENSE Initial commit 3 years ago document `verb` in readme 1 year ago
args.zig Update for multi-for loops 3 months ago
build.zig Update for deprecation of 1 month ago
demo.zig update to new zig module system 4 months ago
demo_verb.zig update to new zig module system 4 months ago
gyro.zzz added string formatter and gyro packaging 2 years ago
pkg.zpm Exports Options from ParseResult, adds ZPM file. 2 years ago
zig.mod Rename zig-args to args 2 years ago

Zig Argument Parser

Simple-to-use argument parser with struct-based config


  • Automatic option generation from a config struct
  • Familiar look & feel:
    • Everything after the first -- is assumed to be a positional argument
    • A single - is interpreted as a positional argument which can be used as the stdin/stdout file placeholder
    • Short options with no argument can be combined into a single argument: -dfe
    • Long options can use either --option=value or --option value syntax (use --option=-- if you need -- as a long option argument)
    • verbs (sub-commands), with verb specific options. Non-verb specific (global) options can come before or after the verb on the command line. Non-verb option arguments are processed before determining verb. (see demo_verb.zig)
  • Integrated support for primitive types:
    • All integer types (signed & unsigned)
    • Floating point types
    • Booleans (takes optional argument. If no argument given, the bool is set, otherwise, one of yes, true, y, no, false, n is interpreted)
    • Strings
    • Enumerations


const options = argsParser.parseForCurrentProcess(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,
    signed_number: ?i64 = null,
    unsigned_number: ?u64 = null,
    mode: enum { default, special, slow, fast } = .default,

    // This declares short-hand options for single hyphen
    pub const shorthands = .{
        .S = "intermix-source",
        .b = "with-hexdump",
        .O = "with-offset",
        .o = "output",
}, argsAllocator, .print) catch return 1;
defer options.deinit();

std.debug.print("executable name: {s}\n", .{options.executable_name});

std.debug.print("parsed options:\n", .{});
inline for (std.meta.fields(@TypeOf(options.options))) |fld| {
    std.debug.print("\t{s} = {any}\n", .{,

std.debug.print("parsed positionals:\n", .{});
for (options.positionals) |arg| {
    std.debug.print("\t'{s}'\n", .{arg});