8 releases (1 stable)

Uses old Rust 2015

1.0.0 Mar 6, 2025
0.1.6 Mar 6, 2025
0.1.4 Sep 8, 2019
0.1.2 Dec 10, 2018
0.1.1 Nov 8, 2018

#88 in Command-line interface

Download history 1699/week @ 2024-12-09 1626/week @ 2024-12-16 1171/week @ 2024-12-23 1010/week @ 2024-12-30 1265/week @ 2025-01-06 1678/week @ 2025-01-13 1626/week @ 2025-01-20 1149/week @ 2025-01-27 1966/week @ 2025-02-03 1454/week @ 2025-02-10 1400/week @ 2025-02-17 1329/week @ 2025-02-24 2096/week @ 2025-03-03 1994/week @ 2025-03-10 2654/week @ 2025-03-17 5544/week @ 2025-03-24

12,406 downloads per month
Used in 39 crates (8 directly)

MITNFA license

28KB
491 lines

Parse arg

Traits and implementations for parsing command-line arguments.

About

This crate provides traits to bridge various libraries providing parsable types with libraries providing command line parsing implementations. The core of the crate is ParseArg trait. It works much like FromStr trait, but with these differences:

  • It operates on &OsStr instead of &str, thus allowing wider range of possible inputs.
  • It provides parse_owned_arg() method which can be specialized to avoid allocations.
  • It requires the implementor to provide describe_type() to print human-readable description. of expected input.
  • It requires the error type to implement Display in order to enable user-friendly interface.

Further, the crate provides ParseArgFromStr trait, which causes any type implementing it to auto-implement ParseArg trait. This is handy when implementing ParseArg for types that already have FromStr implemented, so that boilerplate is reduced.

Any libraries that wish to help their consumers implement parsing their types from command line may add this crate as an optional dependency and implement the ParseArg trait (directly or indirectly) for their types.

Any binaries wishing to use these traits should enable the parse_arg feature of the librariess that use this crate and use a CLI parses implementation crate that uses it too. Currently the only known implementation is configure_me which is also capable of parsing configuration files.

Maintenance status

This crate is considered done. There shouldn't be any updates to it required, so there probably won't be any changes from now. I will accept PRs that fix problems but I don't expect to actively search for things to improve. The crate has only two traits and one enum, so this should be completely fine to use even if it becomes old.

MSRV

The minimum supported Rust version of the crate is 1.63 and will always be whichever Rust version the current Debian stable (12 - Bookworm at the time of writing) supports.

License

MITNFA

No runtime deps