2022-02-06 16:43:51 +08:00
|
|
|
use std::env;
|
|
|
|
use std::fs;
|
|
|
|
|
|
|
|
// ANCHOR: here
|
|
|
|
fn main() {
|
|
|
|
let args: Vec<String> = env::args().collect();
|
|
|
|
|
2023-01-16 17:34:52 +08:00
|
|
|
let (query, file_path) = parse_config(&args);
|
2022-02-06 16:43:51 +08:00
|
|
|
|
|
|
|
// --snip--
|
|
|
|
// ANCHOR_END: here
|
|
|
|
|
|
|
|
println!("Searching for {}", query);
|
2023-01-16 17:34:52 +08:00
|
|
|
println!("In file {}", file_path);
|
2022-02-06 16:43:51 +08:00
|
|
|
|
2023-01-16 17:34:52 +08:00
|
|
|
let contents = fs::read_to_string(file_path)
|
|
|
|
.expect("Should have been able to read the file");
|
2022-02-06 16:43:51 +08:00
|
|
|
|
2023-01-16 17:34:52 +08:00
|
|
|
println!("With text:\n{contents}");
|
2022-02-06 16:43:51 +08:00
|
|
|
// ANCHOR: here
|
|
|
|
}
|
|
|
|
|
|
|
|
fn parse_config(args: &[String]) -> (&str, &str) {
|
|
|
|
let query = &args[1];
|
2023-01-16 17:34:52 +08:00
|
|
|
let file_path = &args[2];
|
2022-02-06 16:43:51 +08:00
|
|
|
|
2023-01-16 17:34:52 +08:00
|
|
|
(query, file_path)
|
2022-02-06 16:43:51 +08:00
|
|
|
}
|
|
|
|
// ANCHOR_END: here
|