#parser #command-line-arguments #auto #error #friendly #messages #pareg

pareg_core

This library contains the implementation for the pareg library

7 releases (4 breaking)

new 0.5.2 Oct 25, 2024
0.5.0 Sep 25, 2024
0.4.0 Jun 25, 2024
0.3.0 Apr 19, 2024
0.1.1 Apr 18, 2024

#2058 in Procedural macros

Download history 16/week @ 2024-06-28 12/week @ 2024-07-05 4/week @ 2024-07-12 2/week @ 2024-07-19 6/week @ 2024-07-26 2/week @ 2024-08-02 5/week @ 2024-08-23 14/week @ 2024-08-30 2/week @ 2024-09-06 22/week @ 2024-09-13 160/week @ 2024-09-20 59/week @ 2024-09-27 15/week @ 2024-10-04 9/week @ 2024-10-11

246 downloads per month
Used in 2 crates

Custom license

53KB
877 lines

pareg

crates.io donwloads

Helpful utilities for parsing command line arguments.

The aim of this crate is not to automate parsing of command line arguments because there are many ways to construct a CLI for your application and universal parser is not would be as hard to use as just writing it yourself. Instead this crate provides useful types and parsing funcitonality to make the process of writing your own code to parse command line arguments as simple as possible: It provides special struct for parsing the arguments in various ways and plenty of useful parsing functions and macros. Everything is made to minimize the repetetive part of the code for parsing the arguments and providing very user friendly error messages out of the box. If you wan't to see examples see docs.

Main constructs:

  • Pareg: istruct that will help with parsing of arguments.
  • FromArg: trait simmilar to FromStr. It is used by all the parsing functionality in this crate. There is also simple derive macro for enums.
    • It is implemented for all types in standard library that implement FromStr and there is simple trait to just mark FromStr implementation as also FromArg: FromArgStr.
  • macros starts_any and has_any_key: useful for checking argument types.

Example error message

argument error: Unknown option `no`.
--> arg1:8..10
 |
 $ my-program --color=no
 |                    ^^ Unknown option.
hint: Valid options are: `auto`, `always`, `never`.

How to use it

Documentation and examples are available at the docs.

How to get it

It is available on crates.io:

With cargo

cargo add pareg

In Cargo.toml

[dependencies]
pareg = "0.1.0"

Dependencies

~1.2–1.8MB
~32K SLoC