I want to pass boolean flags to a program in rust. However, I do not want to use any external crates. How would I do something like that?
Example:
Command: cargo run -- -t
output: -t flag enabled
>Solution :
To hand-roll your CLI, you want to use the std::env module which has the args() function:
https://doc.rust-lang.org/book/ch12-01-accepting-command-line-arguments.html
use std::env;
fn main() {
let args: Vec<String> = env::args().collect();
dbg!(args);
}
So now all you want to do is whether or not the list of arguments contains -t Let me know if you have trouble with that part. 👍