Rust CLI Parser Helper
cli-parser-helper is a lightweight and flexible library for parsing command-line arguments in Rust. It allows you to define CLI options with short and long forms, parse arguments, and retrieve their values or states. The library also generates a help message for your CLI application.
Features
- Register CLI Options: Define options with short forms (e.g.,
-c), long forms (e.g.,--count), and help text. - Parse Arguments: Parse command-line arguments and retrieve normal arguments or option values.
- Check Option States: Determine if an option is enabled or retrieve its associated values.
- Generate Help Text: Automatically generate a help message based on registered options, with a customizable header and footer.
Installation
Add the following to your Cargo.toml:
[]
= "0.1.3"
Usage
Here’s an example of how to use the library:
use CliOptionParser;
API Overview
CliOptionParser
new(header: String, footer: String) -> CliOptionParser
Creates a new parser with a customizable header and footer for the help text.
register_option(short_form: Option<String>, long_form: Option<String>, help_text: &str, name: &str)
Registers a new CLI option with its short form, long form, help text, and name.
parse() -> Vec<String>
Parses the command-line arguments and returns a list of normal arguments.
is_enabled(name: &str) -> bool
Checks if the option with the given name is enabled.
get_option_values(name: &str) -> &Vec<String>
Retrieves the values associated with the given option name.
help_text() -> String
Generates and returns the help text for the CLI options.
Example Output
Given the following command-line input:
The output would be:
Testing
Run the tests using
cargo test
License
This project is licensed under the MIT License.