TAAP
Argument parsing - made easy
What is TAAP?
TAAP is an argument parser made for rust, with ease of use in mind!
(TAAP is short for "totally acceptable argument parser")
This crate provides the Argument struct, which has a couple of implementations which you use to create and parse args. To get started, please take a look at the example down below, which uses this crate to create a simple program with arguments!
(PSST! All this, and more is available over at the docs.rs page)
Quick Start
Adding to your project
To include the crate in your project, either add the following lines to your Cargo.toml file:
[]
= "0.1.4"
or run this command in your cargo project directory:
cargo add taap
When you've added that, you're ready to use TAAP!
Example Usage
In the following codeblock, I'll cover how to add:
- a positional argument
- an optional argument
- some exit statuses
- how to parse the args (and make use of them) (This example/codeblock is also available in the examples folder
// First, import taap so we can use it
use taap;
If you want more "in-depth" explanations and comments, please see the first example in the example folder over in the github repository
Using your software
Now let's run our program!
[user@the_machine taap-rs]$ ./example-1
Error! BAR requires 1 arguments,
We supplied no arguments, which resulted in this output!
Now let's actually supply the arguments. To do this maybe we want to take a look at the help first!
[user@the_machine taap-rs]$ ./example-1 -h
Usage: example-1 BAR [OPTIONS]
The first example program for TAAP!
Positional Arguments:
BAR
Options:
-h --help Use this to print this help message
-f --foo Some help!
--no-help*2
Exit Statuses:
0 Everything went just fine
1 Something went a little wrong
2 Something went horribly wrong!
The text at the bottom of the help!
SpamixOfficial 2023
Hmmm, we didn't define a help argument though? Well, as you see from the output above, TAAP got that covered for us!
When we add arguments, it also automatically adds it to the help! If you also want to print the help yourself, you can call the print_help() function!
Now let's run the program, with the right arguments!
[user@the_machine taap-rs]$ ./example-1 "I am BAR" -f Im_foo --no-help "I take" "Two arguments!"
BAR is: true
Foo was used!
--no-help was used with arguments:
I take
Two arguments!
As you see, all the arguments got parsed and used correctly!
Extra info
If one of the arguments would have had an unspecified amount of arguments (an infinite amount), we would have had to terminate it using -.
That means, that if BAR had an infinite amount of arguments it would have been terminated by the -f option, since the character - terminates the infinite argument.
If we still wanted to use a -, we would have to escape it using \ .
NOTE: Some shells actually uses \ as an escape character, which means you would have to escape the escape character (\\).
Final words
You should now be ready to use TAAP!
If you want to read more about TAAP, there's more documentation on docs.rs
If you want to look at more examples, take a look at the examples folder in this repository
Credits
See CREDITS.md for credits