Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/reokodoku/sap
A simple argument parser library for zig
https://github.com/reokodoku/sap
argument-parser zig zig-package
Last synced: 17 days ago
JSON representation
A simple argument parser library for zig
- Host: GitHub
- URL: https://github.com/reokodoku/sap
- Owner: Reokodoku
- License: mit
- Created: 2024-08-02T10:35:31.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-09-05T19:27:17.000Z (6 months ago)
- Last Synced: 2024-12-06T13:25:03.010Z (2 months ago)
- Topics: argument-parser, zig, zig-package
- Language: Zig
- Homepage:
- Size: 27.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sap
sap is a simple argument parser library for zig that uses a tuple of flags to create a struct containing the value of the arguments.
## How to add the library
1. Run in the terminal:
```sh
zig fetch --save git+https://github.com/Reokodoku/sap
```
2. Add in your `build.zig`:
```zig
const sap = b.dependency("sap", .{});
exe.root_module.addImport("sap", sap.module("sap"));
```## Examples
Minimal example:
```zig
const sap = @import("sap");var arg_parser = sap.Parser(.{
sap.flag([]const u8, "hello", 'h', "world"),
}).init(allocator);
defer arg_parser.deinit();const args = try arg_parser.parseArgs();
std.debug.print("Executable name: {s}\n", .{args.executable_name});
var positionals_iter = args.positionals.iterator();
std.debug.print("Positionals:\n", .{});
while (positionals_iter.next()) |str|
std.debug.print(" {s}\n", .{str});std.debug.print("`hello`|`h` flag value: {s}\n", .{args.hello});
```You can find more examples in the `examples/` folder.
For more information, see the source code or documentation (`zig build docs`).
## Features
* short arguments
* long arguments
* pass values after an equal (`--foo=bar`) or a space (`--foo bar`)
* flags can be specified multiple times
* flags that call a function
* supported types:
* booleans
* strings
* ints (signed and unsigned)
* floats
* enums
* and all optional variants of the above (`?bool`, `?[]const u8`, ...)## Zig version
sap targets the master branch of zig.
In the `build.zig.zon` file, there is the `minimum_zig_version` field which specifies the latest version of zig in which sap compiles.
When the zig master branch breaks the compilation, a commit will be merged to:- fix the compilation errors
- update the `minimum_zig_version` field with the new zig version