All Projects → MasterQ32 → zig-args

MasterQ32 / zig-args

Licence: MIT license
Simple-to-use argument parser with struct-based config

Programming Languages

Zig
133 projects
AMPL
153 projects

Projects that are alternatives of or similar to zig-args

qml zig
QML bindings for the Zig programming language
Stars: ✭ 25 (-76.42%)
Mutual labels:  ziglang, zig-package
zero-graphics
Application framework based on OpenGL ES 2.0. Runs on desktop machines, Android phones and the web
Stars: ✭ 72 (-32.08%)
Mutual labels:  ziglang, zig-package
zlm
Zig linear mathemathics
Stars: ✭ 67 (-36.79%)
Mutual labels:  ziglang, zig-package
ansi-term
Zig library for dealing with ANSI terminals
Stars: ✭ 25 (-76.42%)
Mutual labels:  ziglang, zig-package
IUPforZig
IUP (Portable User Interface Toolkit) bindings for the Zig language.
Stars: ✭ 56 (-47.17%)
Mutual labels:  ziglang, zig-package
zig-opengl
OpenGL binding generator based on the opengl registry
Stars: ✭ 29 (-72.64%)
Mutual labels:  ziglang, zig-package
mach-glfw
Ziggified GLFW bindings with 100% API coverage, zero-fuss installation, cross compilation, and more.
Stars: ✭ 186 (+75.47%)
Mutual labels:  ziglang, zig-package
SDL.zig
A shallow wrapper around SDL that provides object API and error handling
Stars: ✭ 102 (-3.77%)
Mutual labels:  ziglang, zig-package
zetaframe
lightweight zig game framework.
Stars: ✭ 14 (-86.79%)
Mutual labels:  ziglang, zig-package
declarative-parser
Modern, declarative argument parser for Python 3.6+
Stars: ✭ 31 (-70.75%)
Mutual labels:  option-parser, option-parsing
Useful Scripts
🐌 useful scripts for making developer's everyday life easier and happier, involved java, shell etc.
Stars: ✭ 5,835 (+5404.72%)
Mutual labels:  option-parser
Swiftcli
A powerful framework for developing CLIs in Swift
Stars: ✭ 673 (+534.91%)
Mutual labels:  option-parser
Docopt.nim
Command line arguments parser that will make you smile (port of docopt to Nim)
Stars: ✭ 170 (+60.38%)
Mutual labels:  option-parser
VSoft.CommandLineParser
Simple Command Line Options Parser - part of the DUnitX Project
Stars: ✭ 78 (-26.42%)
Mutual labels:  option-parser
Command Line Args
A mature, feature-complete library to parse command-line options.
Stars: ✭ 525 (+395.28%)
Mutual labels:  option-parser
Flag
Flag is a simple but powerful command line option parsing library for Go support infinite level subcommand
Stars: ✭ 114 (+7.55%)
Mutual labels:  option-parser
Kotlin Argparser
Easy to use and concise yet powerful and robust command line argument parsing for Kotlin
Stars: ✭ 431 (+306.6%)
Mutual labels:  option-parser
harg
Haskell program configuration using higher kinded data
Stars: ✭ 23 (-78.3%)
Mutual labels:  option-parser
go-getoptions
Fully featured Go (golang) command line option parser with built-in auto-completion support.
Stars: ✭ 41 (-61.32%)
Mutual labels:  option-parser
line-arg
A command line option parser that uses simple usage strings as a format reference
Stars: ✭ 12 (-88.68%)
Mutual labels:  option-parser

Zig Argument Parser

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

Features

  • 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

Example

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", .{
        fld.name,
        @field(options.options, fld.name),
    });
}

std.debug.print("parsed positionals:\n", .{});
for (options.positionals) |arg| {
    std.debug.print("\t'{s}'\n", .{arg});
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].