Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f9418783d4 | ||
|
|
d7d2c74b23 | ||
|
|
d41577ef7d | ||
|
|
3ff1454fb6 | ||
|
|
a663f2b4d8 |
+10
-2
@@ -7,14 +7,22 @@ struct Cli {
|
|||||||
path: std::path::PathBuf,
|
path: std::path::PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
#[derive(Debug)]
|
||||||
|
struct CustomError(String);
|
||||||
|
|
||||||
|
fn main() -> Result<(), CustomError> {
|
||||||
let args = Cli::parse();
|
let args = Cli::parse();
|
||||||
|
|
||||||
let content = std::fs::read_to_string(&args.path).expect("Could not read file.");
|
// let content = std::fs::read_to_string(&args.path).expect("Could not read file.");
|
||||||
|
|
||||||
|
let content = std::fs::read_to_string(&args.path)
|
||||||
|
.map_err(|err| CustomError(format!("Error reading `{}`: {}", args.path.display(), err)))?;
|
||||||
|
|
||||||
for line in content.lines() {
|
for line in content.lines() {
|
||||||
if line.contains(&args.pattern) {
|
if line.contains(&args.pattern) {
|
||||||
println!("{}", line)
|
println!("{}", line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user