87 releases (breaking)

0.60.2 Mar 26, 2024
0.59.6 Oct 11, 2023
0.59.4 Jan 27, 2023
0.59.3 Nov 23, 2022
0.0.4 May 15, 2018

#96 in Command-line interface

Download history 91/week @ 2024-02-19 31/week @ 2024-02-26 6/week @ 2024-03-11 402/week @ 2024-03-25 357/week @ 2024-04-01

765 downloads per month
Used in 13 crates

LGPL-3.0-or-later

120KB
1.5K SLoC

A command line parser

Project

  • License: GNU Lesser General Public License, either version 3, or (at your option) any later version.
  • This project follows Semantic Versioning 2.0.0

Features

  • No debts. It's an argument parser, so standard Rust is enough.
  • parse_file() helps parse arguments stored in your file.
  • docs helps make documentation for your program.
  • Optional bin feature provides a program which helps you generate simple Rust source code templates. You can run the program with help command for more details.

Specification

A program argument can be:

  • A command.
  • An argument.
  • An option.
  • A special phrase: --.
  1. Commands

    • A command can be anything which does not start with either - or --.
  2. Arguments

    • Same as a command, an argument can be anything which does not start with either - or --.
  3. Options

    An option starts with - or --.

    • - supports a single short format option.

    • -- supports a single long format option.

    • Option values can be anything.

    • An option's key and value can be separated by either:

      • An equals sign =.
      • Or mutiple white spaces.
    • A boolean option has 2 values: true and false. The value is optional. If absent, true will be assigned.

  4. Special phrases

    • -- means: the program should process all phrases after it as arguments. This is normally used to pass arguments to sub process.
  5. Passing arguments to a program

    Must be in this form:

    program [command|arguments...|options...|-] [-- [arguments...]]
    

    in which:

    • [] means optional.
    • ... means multiple arguments.

Dependencies

~130KB