A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/n0s4/flags below:

joegm/flags: An effortless command-line argument parser for Zig.

An effortless command-line argument parser for Zig.

Simply declare a struct and flags will inspect the fields at compile-time to determine how arguments are parsed:

pub fn main() !void {
    var debug_allocator = std.heap.DebugAllocator(.{}).init;
    defer _ = debug_allocator.deinit();
    const gpa = debug_allocator.allocator();

    const args = try std.process.argsAlloc(gpa);
    defer std.process.argsFree(gpa, args);

    const cli = flags.parse(
        args,
        "my-program",

        struct {
            username: []const u8,
        },

        .{},
    );

    try std.io.getStdOut().writer().print("Hello, {s}!\n", .{cli.username});
}

const std = @import("std");
const flags = @import("flags");

flags is intended to be used with the latest Zig release. If flags is out of date, please open an issue.

To import flags to your project, run the following command:

zig fetch --save git+https://github.com/joegm/flags

Then set up the dependency in your build.zig:

    const flags_dep = b.dependency("flags", .{
        .target = target,
        .optimize = optimize,
    })

    exe.root_module.addImport("flags", flags_dep.module("flags"));

See the examples for basic usage.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4