Feat: Use clap for argument parsing.
This commit is contained in:
+5
-7
@@ -1,16 +1,14 @@
|
||||
use clap::Parser;
|
||||
|
||||
// Search for a pattern in a file and display the lines that contain it.
|
||||
#[derive(Parser)]
|
||||
struct Cli {
|
||||
pattern: String,
|
||||
path: std::path::PathBuf,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let pattern = std::env::args().nth(1).expect("no pattern given.");
|
||||
let path = std::env::args().nth(2).expect("no path given.");
|
||||
|
||||
let args = Cli {
|
||||
pattern,
|
||||
path: std::path::PathBuf::from(path),
|
||||
};
|
||||
let args = Cli::parse();
|
||||
|
||||
println!("pattern: {:?}, path: {:?}", args.pattern, args.path)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user