reqwest example combined with cli tutorial
This commit is contained in:
parent
6d3537c084
commit
c4abe1277f
@ -11,7 +11,8 @@ I actually never did this properly. currently reading [this guide](https://clig.
|
|||||||
## Existential crisis
|
## Existential crisis
|
||||||
* ideally a tool on your machine should be easy to install
|
* ideally a tool on your machine should be easy to install
|
||||||
* python versions, venvs etc feels more like a problem here than in a web application
|
* python versions, venvs etc feels more like a problem here than in a web application
|
||||||
* attempt to write something in go?
|
* attempt to write something in rust?
|
||||||
|
* currently following some rust tutorials
|
||||||
|
|
||||||
## Readme driven development
|
## Readme driven development
|
||||||
* have crunk-scheduler do all the conversion to html in rss.
|
* have crunk-scheduler do all the conversion to html in rss.
|
||||||
@ -19,3 +20,4 @@ I actually never did this properly. currently reading [this guide](https://clig.
|
|||||||
- post a simple text
|
- post a simple text
|
||||||
- post markdown or html snippets
|
- post markdown or html snippets
|
||||||
- post files
|
- post files
|
||||||
|
* be able to set a time when something is scheduled.
|
||||||
|
28
src/main.rs
28
src/main.rs
@ -1,3 +1,5 @@
|
|||||||
|
#![deny(warnings)]
|
||||||
|
|
||||||
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.
|
||||||
@ -5,18 +7,24 @@ use clap::Parser;
|
|||||||
|
|
||||||
struct Cli {
|
struct Cli {
|
||||||
url: String,
|
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 args = Cli::parse();
|
||||||
let result = std::fs::read_to_string(&args.path);
|
let url = args.url;
|
||||||
let content = match result {
|
|
||||||
Ok(content) => content,
|
eprintln!("Fetching {:?}...", url);
|
||||||
Err(error) => {
|
let res = reqwest::get(url).await?;
|
||||||
return Err(error.into());
|
|
||||||
}
|
eprintln!("Response: {:?} {}", res.version(), res.status());
|
||||||
};
|
eprintln!("Headers: {:#?}\n", res.headers());
|
||||||
println!("file content: {}", content);
|
let body = res.text().await?;
|
||||||
|
println!("{}", body);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user