Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pstolarz/cmdopts
GNU-like command line options parser in Rust
https://github.com/pstolarz/cmdopts
Last synced: about 1 month ago
JSON representation
GNU-like command line options parser in Rust
- Host: GitHub
- URL: https://github.com/pstolarz/cmdopts
- Owner: pstolarz
- License: bsd-2-clause
- Created: 2023-05-20T20:47:13.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-09-15T13:14:19.000Z (2 months ago)
- Last Synced: 2024-09-15T14:31:14.016Z (2 months ago)
- Language: Rust
- Homepage:
- Size: 22.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![crates.io](https://img.shields.io/crates/v/cmdopts)](https://crates.io/crates/cmdopts)
[![tests](https://github.com/pstolarz/cmdopts/actions/workflows/rust.yml/badge.svg?branch=master)](https://github.com/pstolarz/cmdopts/actions/workflows/rust.yml)
[![docs.rs](https://img.shields.io/docsrs/cmdopts)](https://docs.rs/cmdopts)# Command Line Options Parser
Simple command line parser in Rust.
`cmdopts` parses GNU-like command line options for long and short formats.
Optional argument (aka option's value) may be associated with an option.
The parsing routine `parse_opts()` accepts two user callbacks:
* `opt_i()` provides parser with a context the parsed option may be used,
* `opt_h()` is the actual handler of the option.The library doesn't interpret parsed options, rather passes them to the user's
handler to further processing. The idea is similar to `getopt(3)` and `getopt_long(3)`
routines.## Options Format
### Short format
All options starting with a single hyphen character `-` are short options. For
example: `-a -b -c` constitute 3 short options. These options may grouped into
a single block of options as `-abc`.If a short option requires an argument, the argument may be provided directly
after the option or separated by white-space(s): `-dARG` or `-d ARG`.If short options are grouped into a block, the last one may be provided with
an argument. For example: `-abcdARG` or `-abcd ARG` is equivalent to
`-a -b -c -d ARG`, where `-a` `-b` `-c` don't have an argument, while `-d`
does.### Long format
If an option starts with `--` it's long format option. For example `--help`.
Long options may not be formed into a group. An argument may be provided to
the long-format option directly after `=` character or followed by white-space(s):
`--config=FILE` or `--config FILE`.## Usage
See enclosed [`examples`](examples) for details.
## License
2 clause BSD license. See [`LICENSE`](LICENSE) file for details.