wrapping up
This commit is contained in:
parent
cfc7b1266a
commit
f438c88533
3 changed files with 20 additions and 7 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -52,6 +52,12 @@ dependencies = [
|
||||||
"windows-sys",
|
"windows-sys",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anyhow"
|
||||||
|
version = "1.0.97"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "4.5.35"
|
version = "4.5.35"
|
||||||
|
@ -102,6 +108,7 @@ checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
|
||||||
name = "grrs"
|
name = "grrs"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
"clap",
|
"clap",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -4,4 +4,5 @@ version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
anyhow = "1.0"
|
||||||
clap = { version = "4.0", features = ["derive"] }
|
clap = { version = "4.0", features = ["derive"] }
|
||||||
|
|
19
src/main.rs
19
src/main.rs
|
@ -1,3 +1,4 @@
|
||||||
|
use anyhow::{Context, Result};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
|
@ -6,13 +7,17 @@ struct Cli {
|
||||||
path: std::path::PathBuf,
|
path: std::path::PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
fn main() -> Result<()> {
|
||||||
struct CustomError(String);
|
let args = Cli::parse();
|
||||||
|
|
||||||
|
let content = std::fs::read_to_string(&args.path)
|
||||||
|
.with_context(|| format!("could not read file `{}`", args.path.display()))?;
|
||||||
|
|
||||||
|
for line in content.lines() {
|
||||||
|
if line.contains(&args.pattern) {
|
||||||
|
println!("{}", line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), CustomError> {
|
|
||||||
let path = "test.txt";
|
|
||||||
let content = std::fs::read_to_string(path)
|
|
||||||
.map_err(|err| CustomError(format!("Error reading `{}`: {}", path, err)))?;
|
|
||||||
println!("file content: {}", content);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue