Rust - read input from command line
cargo run -- arG1
#rust fn main() { // This fancy stuff either gets the first argument as a String, or prints // usage and exits if an argument was not supplied to the program. let mut arg: String = std::env::args().nth(1).unwrap_or_else(|| { println!("Please supply an argument to this program."); std::process::exit(-1); }); inspect(&arg); }
Using CLAP cli rust crate
- Links:
Add to Cargo.toml
[dependencies] clap = { version = "4.5.4", features = ["derive"] }