use anyhow::Result as AnyhowResult;
use argh::FromArgs;
use bevy::remote::{
builtin_methods::{BrpQuery, BrpQueryFilter, BrpQueryParams, BRP_QUERY_METHOD},
http::DEFAULT_ADDR,
http::DEFAULT_PORT,
BrpRequest,
};
#[derive(FromArgs)]
struct Args {
#[argh(option, default = "DEFAULT_ADDR.to_string()")]
host: String,
#[argh(option, default = "DEFAULT_PORT")]
port: u16,
#[argh(positional, greedy)]
components: Vec<String>,
}
fn main() -> AnyhowResult<()> {
let args: Args = argh::from_env();
let host_part = format!("{}:{}", args.host, args.port);
let url = format!("http://{}/", host_part);
let req = BrpRequest {
jsonrpc: String::from("2.0"),
method: String::from(BRP_QUERY_METHOD),
id: Some(ureq::json!(1)),
params: Some(
serde_json::to_value(BrpQueryParams {
data: BrpQuery {
components: args.components,
option: Vec::default(),
has: Vec::default(),
},
filter: BrpQueryFilter::default(),
})
.expect("Unable to convert query parameters to a valid JSON value"),
),
};
let res = ureq::post(&url)
.send_json(req)?
.into_json::<serde_json::Value>()?;
println!("{:#}", res);
Ok(())
}