crunk
1 year ago
1 changed files with 11 additions and 8 deletions
@ -1,19 +1,22 @@ |
|||||
#![allow(unused)] |
|
||||
use clap::Parser; |
use clap::Parser; |
||||
|
|
||||
/// Search for a pattern in a file and display the lines that contain it.
|
/// Search for a pattern in a file and display the lines that contain it.
|
||||
#[derive(Parser)] |
#[derive(Parser)] |
||||
|
|
||||
struct Cli { |
struct Cli { |
||||
pattern: String, |
url: String, |
||||
path: std::path::PathBuf, |
path: std::path::PathBuf, |
||||
} |
} |
||||
|
|
||||
fn main() { |
fn main() -> Result<(), Box<dyn std::error::Error>> { |
||||
let args = Cli::parse(); |
let args = Cli::parse(); |
||||
println!("pattern: {}", args.pattern); |
let result = std::fs::read_to_string(&args.path); |
||||
println!( |
let content = match result { |
||||
"path: {}", |
Ok(content) => content, |
||||
args.path.into_os_string().into_string().unwrap() |
Err(error) => { |
||||
); |
return Err(error.into()); |
||||
|
} |
||||
|
}; |
||||
|
println!("file content: {}", content); |
||||
|
Ok(()) |
||||
} |
} |
||||
|
Loading…
Reference in new issue