blob: 76b25438b7f5fb429da0b67b1acffa5311249737 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
use std::error::Error;
use std::process;
use std::fs;
use clap::Parser;
#[derive(Parser)]
#[command(author, version, about, long_about = None)] // Read from `Cargo.toml`
struct Config {
/// The pattern to look for
pattern: String,
/// The path to the file to read
file: String,
}
fn main() {
let config = Config::parse();
if let Err(e) = run(config) {
eprintln!("Error: {e}");
process::exit(1);
}
}
fn run(config: Config) -> Result<(), Box<dyn Error>> {
let contents = fs::read_to_string(config.file)?;
for line in trgrep::search(&config.pattern, &contents) {
println!("{line}");
}
Ok(())
}
|