Skip to content

atisans/flags.zig

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flags.zig

A comprehensive command-line flag parser for Zig, inspired by Go's flags package.

Features

  • ✅ Multiple flag types (bool, string, int, float, duration)
  • ✅ Automatic help generation (-h, -help)
  • ✅ Positional arguments support
  • ✅ Short flag names (-v)
  • ✅ Flag sets for subcommands
  • ✅ Custom flag types via Value interface
  • ✅ Configurable error handling
  • ✅ Environment variable integration (planned)
  • ✅ Configuration file support (planned)

Installation

fetch library

zig fetch https://github.com/<username>/flags.zig/archive/main.tar.gz --name=flags

or add to your build.zig.zon:

.dependencies = .{
    .flags = .{
        .url = "https://github.com/<username>/flags.zig/archive/main.tar.gz",
        .hash = "...",
    },
},

Basic Usage

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

pub fn main() !void {
    flags.parse();    // Parse command line

    // Define flags
    const name = flags.string("name", "world", "name to greet");
    const age = flags.int("age", 25, "your age");
    const verbose = flags.boolean("verbose", false, "verbose output");

    // Use the values
    std.debug.print("Hello {s}! Age: {}, Verbose: {}\n", .{name, age, verbose});
}

Command Line Examples

# Basic usage
./program -name=alice -age=30 -verbose

# Short flags (when implemented)
./program -n alice -a 30 -v

# Help
./program -h # or (--help)

# With positional arguments (when implemented)
./program -name=bob file1.txt file2.txt

About

command line flag parser similar to the in-built one in Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages