Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
n0s4 authored May 17, 2024
1 parent c508346 commit 8632348
Showing 1 changed file with 3 additions and 56 deletions.
59 changes: 3 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,64 +1,11 @@
# Arguments

A powerful, practical command-line argument parser for Zig that won't get in your way.

## Demo

```zig
const std = @import("std");
const arguments = @import("arguments");
const Config = struct {
// bools and optionals will be set to false/null if their flags are not passed:
force: bool,
target: ?[]const u8,
// non-optional types can have a default, or be required:
override: []const u8 = "defaulty",
required: []const u8,
// ints are parsed automatically:
age: ?u8,
power: i32 = 9000,
// restrict choice with enums:
use_color: enum { never, auto, always } = .auto,
job: ?enum { ceo, software_developer, product_manager },
/// This field is required for storing positional arguments.
/// A global-scoped fixed buffer is used during parsing to store these to avoid allocation,
/// this is a slice into that buffer.
args: []const []const u8,
/// Optional declaration defines shorthands which can be chained e.g '-ft foo'.
/// Note that this must be marked `pub`.
pub const switches = .{
.force = 'f',
.target = 't',
.override = 'o',
.required = 'r',
.age = 'a',
.power = 'p',
.use_color = 'c',
.job = 'j',
};
};
pub fn main() !void {
var args = std.process.args();
const result = arguments.parse(&args, Config);
printConfig(result);
}
```

```
$ ./path/to/myprogram -fa 21 --required foo --use-color always bar baz
```
A command-line argument parser for Zig.

## Getting Started

See the [examples](examples/) for basic usage.

Check out the [import guide](https://github.com/n0s4/Arguments/wiki/Importing) to get set up using Arguments in your project.

## Goals
Expand Down

0 comments on commit 8632348

Please sign in to comment.