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!
# Adding to your project
To include the crate in your project, either add the following lines to your `Cargo.toml` file:
```toml
[dependencies]
taap = "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](https://github.com/SpamixOfficial/taap-rs/tree/master/examples) in the [github
repository](https://github.com/SpamixOfficial/taap-rs))
```rust
use taap;
fn main() {
let mut arguments = taap::Argument::new("example-1", "The first example program for TAAP!", "The text at the bottom of the help!", "SpamixOfficial 2023");
arguments.add_option('f', "foo", "0", Some("Some help!"));
arguments.add_option('-', "no-help", "2", None);
arguments.add_arg("BAR", "1", None);
arguments.add_exit_status(0, "Everything went just fine");
arguments.add_exit_status(1, "Something went a little wrong");
arguments.add_exit_status(2, "Something went horribly wrong!");
let parsed_arguments = arguments.parse_args(None);
let bar = parsed_arguments.get("BAR").unwrap();
println!("BAR is: {}", bar.0);
let foo = parsed_arguments.get("f").unwrap();
was_foo_used(foo);
let no_help = parsed_arguments.get("no-help").unwrap();
if no_help.0 {
println!("--no-help was used with arguments:");
for argument in no_help.1.iter() {
println!("{}", argument);
};
} else {
println!("--no--help was not used!");
};
}
fn was_foo_used(info: &(bool, Vec<String>)) {
if info.0 {
println!("Foo was used!");
} else {
println!("Foo was not used!");
};
}
```
# Using your software
Now let's run our program!
```text
[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!
```text
[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!
```text
[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 this page
If you want to look at more examples, take a look at the [examples
folder](https://github.com/SpamixOfficial/taap-rs/tree/master/examples) in the [github
repository](https://github.com/SpamixOfficial/taap-rs)