You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Matt Knight d10482c9bd Vendor (#19)
* vendor dependencies
7 months ago
..
README.md.template Vendor (#19) 7 months ago
help.zig Vendor (#19) 7 months ago
simple-ex.zig Vendor (#19) 7 months ago
simple.zig Vendor (#19) 7 months ago
streaming-clap.zig Vendor (#19) 7 months ago
usage.zig Vendor (#19) 7 months ago

README.md.template

<!---
README.md is autogenerated. Please edit example/README.md.template instead.
-->
# zig-clap

A simple and easy to use command line argument parser library for Zig.

## Features

* Short arguments `-a`
  * Chaining `-abc` where `a` and `b` does not take values.
* Long arguments `--long`
* Supports both passing values using spacing and `=` (`-a 100`, `-a=100`)
  * Short args also support passing values with no spacing or `=` (`-a100`)
  * This all works with chaining (`-ba 100`, `-ba=100`, `-ba100`)
* Supports options that can be specified multiple times (`-e 1 -e 2 -e 3`)
* Print help message from parameter specification.
* Parse help message to parameter specification.

## Examples

### `clap.parse`

The simplest way to use this library is to just call the `clap.parse` function.

```zig
{s}
```

The result will contain an `args` field and a `positionals` field. `args` will have one field
for each none positional parameter of your program. The name of the field will be the longest
name of the parameter.

The fields in `args` are typed. The type is based on the name of the value the parameter takes.
Since `--number` takes a `usize` the field `res.args.number` has the type `usize`.

Note that this is only the case because `clap.parsers.default` has a field called `usize` which
contains a parser that returns `usize`. You can pass in something other than
`clap.parsers.default` if you want some other mapping.

```zig
{s}
```

### `streaming.Clap`

The `streaming.Clap` is the base of all the other parsers. It's a streaming parser that uses an
`args.Iterator` to provide it with arguments lazily.

```zig
{s}
```

Currently, this parser is the only parser that allows an array of `Param` that
is generated at runtime.

### `help`

The `help` prints a simple list of all parameters the program can take. It expects the
`Id` to have a `description` method and an `value` method so that it can provide that
in the output. `HelpOptions` is passed to `help` to control how the help message is
printed.

```zig
{s}
```

```
$ zig-out/bin/help --help
    -h, --help
            Display this help and exit.

    -v, --version
            Output version information and exit.
```

### `usage`

The `usage` prints a small abbreviated version of the help message. It expects the `Id`
to have a `value` method so it can provide that in the output.

```zig
{s}
```

```
$ zig-out/bin/usage --help
[-hv] [--value <str>]
```