15 releases (6 breaking)

0.7.3 Dec 23, 2024
0.7.2 Nov 25, 2024
0.6.0 Nov 21, 2024
0.5.1 Nov 21, 2024
0.1.2 Jul 23, 2023

#503 in Command-line interface

Download history 7/week @ 2024-09-20 578/week @ 2024-09-27 78/week @ 2024-10-04 31/week @ 2024-10-11 3/week @ 2024-10-18 14/week @ 2024-11-01 5/week @ 2024-11-08 436/week @ 2024-11-15 601/week @ 2024-11-22 37/week @ 2024-11-29 2/week @ 2024-12-06 124/week @ 2024-12-20 15/week @ 2024-12-27

141 downloads per month

GPL-3.0-or-later

18KB
232 lines

argsyn, an Argument Parser for GNU-style Syntax

This crate provides a complete implementation of GNU-style argument parsing as described at
https://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html

Arguments are converted into basics, flags, pairs, and a few other types according to the GNU-style. Here is a visual example of how a sequence of arguments is converted with "xy" specified as short pairs:

$ program arg1 -abcx12 -y 3 --long --key=value - arg2 -- -kh --ignore
  |       |     ||||    |     |      |         | |    |  |   |
  Basic(program)||||    |     |      |         | |    |  Basic(-kh)
          Basic(arg1)   |     |      |         | |    |      Basic(--ignore)
                Flag(a) |     |      |         | |    |
                 Flag(b)|     |      |         | |    |
                  Flag(c)     |      |         | |    |
                   Pair(x,12) |      |         | |    |
                        Pair(y,3)    |         | |    |
                              Flag(long)       | |    |
                                     Pair(key,value)  |
                                               Stdin  |
                                                 Basic(arg2)
                                                      Done

In Rust, to print all arguments parsed, it is as simple as:

for opt in std::env::args().opts("xy").unwrap() {
  println!("{:?}", opt.simplify());
}

Dependencies

~250–700KB
~17K SLoC