|
|
@ -1,3 +1,5 @@ |
|
|
|
#![deny(warnings)] |
|
|
|
|
|
|
|
use clap::Parser; |
|
|
|
|
|
|
|
/// Search for a pattern in a file and display the lines that contain it.
|
|
|
@ -5,18 +7,24 @@ use clap::Parser; |
|
|
|
|
|
|
|
struct Cli { |
|
|
|
url: String, |
|
|
|
path: std::path::PathBuf, |
|
|
|
} |
|
|
|
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> { |
|
|
|
// This is using the `tokio` runtime. You'll need the following dependency:
|
|
|
|
//
|
|
|
|
// `tokio = { version = "1", features = ["full"] }`
|
|
|
|
#[cfg(not(target_arch = "wasm32"))] |
|
|
|
#[tokio::main] |
|
|
|
async fn main() -> Result<(), reqwest::Error> { |
|
|
|
// Some simple CLI args requirements...
|
|
|
|
let args = Cli::parse(); |
|
|
|
let result = std::fs::read_to_string(&args.path); |
|
|
|
let content = match result { |
|
|
|
Ok(content) => content, |
|
|
|
Err(error) => { |
|
|
|
return Err(error.into()); |
|
|
|
} |
|
|
|
}; |
|
|
|
println!("file content: {}", content); |
|
|
|
let url = args.url; |
|
|
|
|
|
|
|
eprintln!("Fetching {:?}...", url); |
|
|
|
let res = reqwest::get(url).await?; |
|
|
|
|
|
|
|
eprintln!("Response: {:?} {}", res.version(), res.status()); |
|
|
|
eprintln!("Headers: {:#?}\n", res.headers()); |
|
|
|
let body = res.text().await?; |
|
|
|
println!("{}", body); |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|