https://github.com/fjebaker/clippy
A comptime-configured argument parser for Zig with help and completion generation.
https://github.com/fjebaker/clippy
Last synced: about 1 year ago
JSON representation
A comptime-configured argument parser for Zig with help and completion generation.
- Host: GitHub
- URL: https://github.com/fjebaker/clippy
- Owner: fjebaker
- License: gpl-3.0
- Created: 2024-03-17T19:14:26.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-16T15:05:59.000Z (about 1 year ago)
- Last Synced: 2025-04-05T01:06:58.401Z (about 1 year ago)
- Language: Zig
- Size: 175 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# clippy
A pretty minimal declarative compile time argument parser.
## Usage
See the `examples` directory for more example uses. The basic usage for parsing simple arguments is:
```zig
const std = @import("std");
const clippy = @import("clippy");
const Arguments = clippy.Arguments(&.{
.{
.arg = "file",
.help = "Path to file.",
.required = true,
},
.{
.arg = "-v",
.help = "Verbose.",
},
.{
.arg = "-a/--algorithm alg",
.help = "Which algorithm to use (by index).",
.argtype = usize,
.default = "2",
},
});
pub fn main() !void {
// ...
const args = try std.process.argsAlloc(allocator);
defer std.process.argsFree(allocator, args);
// miss out the program name, unless you want to parse it
var itt = clippy.ArgumentIterator.init(args[1..]);
var parser = Arguments.init(&itt, .{});
const parsed = try parser.parseAll();
std.debug.print("File : {s}\n", .{parsed.file});
std.debug.print("Verbose : {any}\n", .{parsed.v});
std.debug.print("Alg : {d}\n", .{parsed.algorithm});
// ...
try Arguments.writeHelp(writer, .{});
// ...
}
```