|
|
@ -1,6 +1,7 @@ |
|
|
|
#![deny(warnings)] |
|
|
|
|
|
|
|
use clap::Parser; |
|
|
|
use reqwest::blocking::multipart; |
|
|
|
|
|
|
|
/// Search for a pattern in a file and display the lines that contain it.
|
|
|
|
#[derive(Parser)] |
|
|
@ -9,27 +10,31 @@ use clap::Parser; |
|
|
|
#[command(version = "1.0")] |
|
|
|
#[command(about = "post updates to crunk-schedulers", long_about = None)] |
|
|
|
struct Cli { |
|
|
|
#[arg(long)] |
|
|
|
#[arg(short, long)] |
|
|
|
url: String, |
|
|
|
#[arg(long)] |
|
|
|
text: String, |
|
|
|
#[arg(short, long, group = "input")] |
|
|
|
text: Option<String>, |
|
|
|
#[arg(short, long, group = "input")] |
|
|
|
file: Option<String>, |
|
|
|
} |
|
|
|
|
|
|
|
#[cfg(not(target_arch = "wasm32"))] |
|
|
|
#[tokio::main] |
|
|
|
|
|
|
|
async fn main() -> Result<(), reqwest::Error> { |
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> { |
|
|
|
let args = Cli::parse(); |
|
|
|
let url = args.url; |
|
|
|
let text = args.text; |
|
|
|
if text.is_some() { |
|
|
|
let client = reqwest::blocking::Client::new(); |
|
|
|
let res = client.post(url).form(&[("text", text)]).send()?; |
|
|
|
println!("{:?}", res); |
|
|
|
} |
|
|
|
if args.file.is_some() { |
|
|
|
let file_name = args.file.as_deref().unwrap_or_default(); |
|
|
|
let client = reqwest::blocking::Client::new(); |
|
|
|
let form = multipart::Form::new().file("file", &file_name)?; |
|
|
|
|
|
|
|
let client = reqwest::Client::new(); |
|
|
|
let res = client.post(url).form(&[("text", text)]).send().await?; |
|
|
|
|
|
|
|
eprintln!("Response: {:?} {}", res.version(), res.status()); |
|
|
|
eprintln!("Headers: {:#?}\n", res.headers()); |
|
|
|
|
|
|
|
let body = res.text().await?; |
|
|
|
println!("{}", body); |
|
|
|
let res = client.post("your url").multipart(form).send()?; |
|
|
|
println!("{:?}", res) |
|
|
|
} |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|