From ac1ce0cede811ba9c1e7b971ba4b0a56de59838b Mon Sep 17 00:00:00 2001 From: augustuswm Date: Mon, 16 Oct 2023 15:35:47 -0500 Subject: [PATCH 1/4] Add - as an alias for standard in when specifying a json body --- progenitor-impl/src/cli.rs | 21 +- .../tests/output/buildomat-cli.out | 128 +- progenitor-impl/tests/output/keeper-cli.out | 86 +- progenitor-impl/tests/output/nexus-cli.out | 1208 +++++++++++++---- .../tests/output/propolis-server-cli.out | 84 +- 5 files changed, 1166 insertions(+), 361 deletions(-) diff --git a/progenitor-impl/src/cli.rs b/progenitor-impl/src/cli.rs index e03067b2..6b97f5b8 100644 --- a/progenitor-impl/src/cli.rs +++ b/progenitor-impl/src/cli.rs @@ -440,7 +440,7 @@ impl Generator { CliBodyArg::Optional => Some(false), }) .map(|required| { - let help = "Path to a file that contains the full json body."; + let help = r#"Path to a file that contains the full json body (use "-" to read from standard input)."#; quote! { .arg( @@ -450,7 +450,7 @@ impl Generator { // Required if we can't turn the body into individual // parameters. .required(#required) - .value_parser(clap::value_parser!(std::path::PathBuf)) + .value_parser(clap::value_parser!(String)) .help(#help) ) .arg( @@ -477,12 +477,21 @@ impl Generator { let body_type_ident = body_type.ident(); quote! { if let Some(value) = - matches.get_one::("json-body") + matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap() + }; + let body_value = - serde_json::from_str::<#body_type_ident>( - &body_txt, + serde_json::from_slice::<#body_type_ident>( + &body_input, ) .unwrap(); request = request.body(body_value); diff --git a/progenitor-impl/tests/output/buildomat-cli.out b/progenitor-impl/tests/output/buildomat-cli.out index 02c3a6a1..3d8d4e33 100644 --- a/progenitor-impl/tests/output/buildomat-cli.out +++ b/progenitor-impl/tests/output/buildomat-cli.out @@ -72,8 +72,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -137,8 +140,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -175,8 +181,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -221,8 +230,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -260,8 +272,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -296,8 +311,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -457,9 +475,17 @@ impl Cli { request = request.body_map(|body| body.script(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -551,9 +577,17 @@ impl Cli { request = request.body_map(|body| body.name(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -611,9 +645,17 @@ impl Cli { request = request.body_map(|body| body.token(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -665,9 +707,18 @@ impl Cli { request = request.body_map(|body| body.time(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -715,9 +766,18 @@ impl Cli { request = request.task(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -749,9 +809,17 @@ impl Cli { request = request.task(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } diff --git a/progenitor-impl/tests/output/keeper-cli.out b/progenitor-impl/tests/output/keeper-cli.out index fc3e41b6..8e4e2c4a 100644 --- a/progenitor-impl/tests/output/keeper-cli.out +++ b/progenitor-impl/tests/output/keeper-cli.out @@ -45,8 +45,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -108,8 +111,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -133,8 +139,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -170,8 +179,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -224,9 +236,17 @@ impl Cli { request = request.body_map(|body| body.key(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -298,9 +318,18 @@ impl Cli { request = request.body_map(|body| body.exit_status(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -324,9 +353,18 @@ impl Cli { request = request.authorization(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -359,9 +397,17 @@ impl Cli { request = request.body_map(|body| body.start_time(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } diff --git a/progenitor-impl/tests/output/nexus-cli.out b/progenitor-impl/tests/output/nexus-cli.out index 3d94453d..9d8ecc70 100644 --- a/progenitor-impl/tests/output/nexus-cli.out +++ b/progenitor-impl/tests/output/nexus-cli.out @@ -354,8 +354,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -384,8 +387,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -426,8 +432,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -478,8 +487,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -514,8 +526,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -613,8 +628,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -665,8 +683,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -718,8 +739,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -790,8 +814,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -856,8 +883,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -967,8 +997,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -1160,8 +1193,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -1331,8 +1367,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -1464,8 +1503,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -1508,8 +1550,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -1575,8 +1620,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -1690,8 +1738,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -1790,8 +1841,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -2031,8 +2085,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -2120,8 +2177,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -2267,8 +2327,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -2345,8 +2408,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -2428,8 +2494,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -2518,8 +2587,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -2602,8 +2674,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -2734,8 +2809,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -2830,8 +2908,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -2978,8 +3059,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -3062,8 +3146,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -3161,8 +3248,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -3274,8 +3364,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -3405,8 +3498,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -3614,8 +3710,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -3702,8 +3801,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -3750,8 +3852,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -3805,8 +3910,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -3830,8 +3938,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -3866,8 +3977,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -3885,8 +3999,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -3961,8 +4078,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -4084,8 +4204,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -4173,8 +4296,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -4230,8 +4356,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -4317,8 +4446,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -4374,8 +4506,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -4580,8 +4715,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -4742,8 +4880,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -4874,8 +5015,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -4917,8 +5061,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -4960,8 +5107,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -5165,8 +5315,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -5213,8 +5366,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -5260,8 +5416,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -5328,8 +5487,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -5388,8 +5550,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -5453,8 +5618,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -5539,8 +5707,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -6425,9 +6596,18 @@ impl Cli { request = request.body_map(|body| body.client_id(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -6451,9 +6631,18 @@ impl Cli { request = request.body_map(|body| body.user_code(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -6485,10 +6674,18 @@ impl Cli { request = request.body_map(|body| body.grant_type(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; let body_value = - serde_json::from_str::(&body_txt).unwrap(); + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -6540,9 +6737,17 @@ impl Cli { request = request.body_map(|body| body.username(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -6574,10 +6779,18 @@ impl Cli { request = request.body_map(|body| body.username(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; let body_value = - serde_json::from_str::(&body_txt).unwrap(); + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -6695,9 +6908,18 @@ impl Cli { request = request.body_map(|body| body.name(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -6749,9 +6971,18 @@ impl Cli { request = request.organization_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -6815,10 +7046,18 @@ impl Cli { request = request.organization_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; let body_value = - serde_json::from_str::(&body_txt).unwrap(); + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -6884,9 +7123,17 @@ impl Cli { request = request.organization_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -6946,9 +7193,17 @@ impl Cli { request = request.project_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -7048,9 +7303,17 @@ impl Cli { request = request.body_map(|body| body.size(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -7227,9 +7490,17 @@ impl Cli { request = request.project_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -7377,9 +7648,17 @@ impl Cli { request = request.body_map(|body| body.user_data(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -7513,9 +7792,17 @@ impl Cli { request = request.project_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -7551,9 +7838,17 @@ impl Cli { request = request.project_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -7617,9 +7912,17 @@ impl Cli { request = request.project_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -7713,10 +8016,18 @@ impl Cli { request = request.body_map(|body| body.vpc_name(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; let body_value = - serde_json::from_str::(&body_txt).unwrap(); + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -7796,10 +8107,18 @@ impl Cli { request = request.project_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; let body_value = - serde_json::from_str::(&body_txt).unwrap(); + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8035,9 +8354,18 @@ impl Cli { request = request.project_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8115,9 +8443,17 @@ impl Cli { request = request.project_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8253,9 +8589,17 @@ impl Cli { request = request.project_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8323,9 +8667,17 @@ impl Cli { request = request.vpc_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8409,10 +8761,18 @@ impl Cli { request = request.vpc_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; let body_value = - serde_json::from_str::(&body_txt).unwrap(); + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8494,9 +8854,17 @@ impl Cli { request = request.vpc_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8572,9 +8940,17 @@ impl Cli { request = request.vpc_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8696,10 +9072,18 @@ impl Cli { request = request.vpc_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; let body_value = - serde_json::from_str::(&body_txt).unwrap(); + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8783,10 +9167,18 @@ impl Cli { request = request.vpc_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; let body_value = - serde_json::from_str::(&body_txt).unwrap(); + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8912,9 +9304,17 @@ impl Cli { request = request.vpc_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8990,9 +9390,17 @@ impl Cli { request = request.vpc_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -9106,9 +9514,17 @@ impl Cli { pub async fn execute_policy_update(&self, matches: &clap::ArgMatches) { let mut request = self.client.policy_update(); - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -9256,9 +9672,17 @@ impl Cli { request = request.body_map(|body| body.public_key(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -9420,9 +9844,18 @@ impl Cli { request = request.body_map(|body| body.service(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -9676,9 +10109,18 @@ impl Cli { request = request.body_map(|body| body.name(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -9776,9 +10218,17 @@ impl Cli { request = request.body_map(|body| body.name(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -9830,9 +10280,17 @@ impl Cli { request = request.pool_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -9906,9 +10364,17 @@ impl Cli { request = request.pool_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -9932,9 +10398,17 @@ impl Cli { request = request.pool_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -9996,9 +10470,17 @@ impl Cli { pub async fn execute_ip_pool_service_range_add(&self, matches: &clap::ArgMatches) { let mut request = self.client.ip_pool_service_range_add(); - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10018,9 +10500,17 @@ impl Cli { pub async fn execute_ip_pool_service_range_remove(&self, matches: &clap::ArgMatches) { let mut request = self.client.ip_pool_service_range_remove(); - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10097,9 +10587,17 @@ impl Cli { pub async fn execute_system_policy_update(&self, matches: &clap::ArgMatches) { let mut request = self.client.system_policy_update(); - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10213,9 +10711,17 @@ impl Cli { request = request.body_map(|body| body.name(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10315,9 +10821,17 @@ impl Cli { request = request.silo_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10369,9 +10883,17 @@ impl Cli { request = request.user_id(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10427,10 +10949,18 @@ impl Cli { request = request.body_map(|body| body.technical_contact_email(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; let body_value = - serde_json::from_str::(&body_txt).unwrap(); + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10498,9 +11028,17 @@ impl Cli { request = request.silo_name(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10740,9 +11278,17 @@ impl Cli { request = request.body_map(|body| body.size(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10892,9 +11438,17 @@ impl Cli { request = request.body_map(|body| body.user_data(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -11028,9 +11582,17 @@ impl Cli { request = request.project(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -11066,9 +11628,17 @@ impl Cli { request = request.project(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -11104,9 +11674,17 @@ impl Cli { request = request.project(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -11316,9 +11894,18 @@ impl Cli { request = request.body_map(|body| body.name(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -11370,9 +11957,18 @@ impl Cli { request = request.organization(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -11436,10 +12032,18 @@ impl Cli { request = request.organization(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; let body_value = - serde_json::from_str::(&body_txt).unwrap(); + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -11505,9 +12109,17 @@ impl Cli { request = request.organization(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -11567,9 +12179,17 @@ impl Cli { request = request.project(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -11645,9 +12265,18 @@ impl Cli { request = request.project(value.clone()); } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -11767,9 +12396,18 @@ impl Cli { request = request.body_map(|body| body.version(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); - let body_value = serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; + let body_value = + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } diff --git a/progenitor-impl/tests/output/propolis-server-cli.out b/progenitor-impl/tests/output/propolis-server-cli.out index 6cdb4c0f..373221cf 100644 --- a/progenitor-impl/tests/output/propolis-server-cli.out +++ b/progenitor-impl/tests/output/propolis-server-cli.out @@ -39,8 +39,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -80,8 +83,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -102,8 +108,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(true) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -126,8 +135,11 @@ impl Cli { .long("json-body") .value_name("JSON-FILE") .required(false) - .value_parser(clap::value_parser!(std::path::PathBuf)) - .help("Path to a file that contains the full json body."), + .value_parser(clap::value_parser!(String)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( clap::Arg::new("json-body-template") @@ -192,10 +204,18 @@ impl Cli { request = request.body_map(|body| body.cloud_init_bytes(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; let body_value = - serde_json::from_str::(&body_txt).unwrap(); + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -246,10 +266,18 @@ impl Cli { request = request.body_map(|body| body.migration_id(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; let body_value = - serde_json::from_str::(&body_txt).unwrap(); + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -285,10 +313,18 @@ impl Cli { pub async fn execute_instance_state_put(&self, matches: &clap::ArgMatches) { let mut request = self.client.instance_state_put(); - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; let body_value = - serde_json::from_str::(&body_txt).unwrap(); + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -312,10 +348,18 @@ impl Cli { request = request.body_map(|body| body.gen(value.clone())) } - if let Some(value) = matches.get_one::("json-body") { - let body_txt = std::fs::read_to_string(value).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + use std::io::Read; + let body_input = match value.as_str() { + "-" => { + let mut buf = Vec::new(); + std::io::stdin().read_to_end(&mut buf).unwrap(); + buf + } + file => std::fs::read(&file).unwrap(), + }; let body_value = - serde_json::from_str::(&body_txt).unwrap(); + serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } From 288a491c3e03f1da2b849d6d14bc0245d42b3a7f Mon Sep 17 00:00:00 2001 From: augustuswm Date: Thu, 19 Oct 2023 17:16:53 -0500 Subject: [PATCH 2/4] Use serde reader method --- progenitor-impl/src/cli.rs | 16 +- .../tests/output/buildomat-cli.out | 74 +- progenitor-impl/tests/output/keeper-cli.out | 50 +- progenitor-impl/tests/output/nexus-cli.out | 705 +++++------------- .../tests/output/propolis-server-cli.out | 52 +- 5 files changed, 216 insertions(+), 681 deletions(-) diff --git a/progenitor-impl/src/cli.rs b/progenitor-impl/src/cli.rs index 6b97f5b8..dde45d41 100644 --- a/progenitor-impl/src/cli.rs +++ b/progenitor-impl/src/cli.rs @@ -479,21 +479,11 @@ impl Generator { if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap() + let body_value: #body_type_ident = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::<#body_type_ident>( - &body_input, - ) - .unwrap(); request = request.body(body_value); } } diff --git a/progenitor-impl/tests/output/buildomat-cli.out b/progenitor-impl/tests/output/buildomat-cli.out index 3d8d4e33..7bee3b1b 100644 --- a/progenitor-impl/tests/output/buildomat-cli.out +++ b/progenitor-impl/tests/output/buildomat-cli.out @@ -476,16 +476,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::TaskSubmit = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -578,16 +572,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::UserCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -646,16 +634,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::WorkerBootstrap = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -708,17 +690,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::WorkerAppendTask = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -767,17 +742,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::WorkerCompleteTask = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -810,16 +778,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::WorkerAddOutput = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } diff --git a/progenitor-impl/tests/output/keeper-cli.out b/progenitor-impl/tests/output/keeper-cli.out index 8e4e2c4a..eb2bfbeb 100644 --- a/progenitor-impl/tests/output/keeper-cli.out +++ b/progenitor-impl/tests/output/keeper-cli.out @@ -237,16 +237,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::EnrolBody = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -319,17 +313,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::ReportFinishBody = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -354,17 +341,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::ReportOutputBody = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -398,16 +378,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::ReportStartBody = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } diff --git a/progenitor-impl/tests/output/nexus-cli.out b/progenitor-impl/tests/output/nexus-cli.out index 9d8ecc70..011693df 100644 --- a/progenitor-impl/tests/output/nexus-cli.out +++ b/progenitor-impl/tests/output/nexus-cli.out @@ -6597,17 +6597,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::DeviceAuthRequest = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -6632,17 +6625,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::DeviceAuthVerify = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -6675,17 +6661,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::DeviceAccessTokenRequest = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -6738,16 +6717,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::SpoofLoginBody = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -6780,17 +6753,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::UsernamePasswordCredentials = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -6909,17 +6875,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::OrganizationCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -6972,17 +6931,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::OrganizationUpdate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -7047,17 +6999,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::OrganizationRolePolicy = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -7124,16 +7069,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::ProjectCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -7194,16 +7133,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::ProjectUpdate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -7304,16 +7237,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::DiskCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -7491,16 +7418,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::ImageCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -7649,16 +7570,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::InstanceCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -7793,16 +7708,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::DiskIdentifier = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -7839,16 +7748,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::DiskIdentifier = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -7913,16 +7816,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::InstanceMigrate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8017,17 +7914,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::NetworkInterfaceCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8108,17 +7998,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::NetworkInterfaceUpdate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8355,17 +8238,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::ProjectRolePolicy = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8444,16 +8320,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::SnapshotCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8590,16 +8460,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::VpcCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8668,16 +8532,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::VpcUpdate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8762,17 +8620,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::VpcFirewallRuleUpdateParams = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8855,16 +8706,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::VpcRouterCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -8941,16 +8786,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::VpcRouterUpdate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -9073,17 +8912,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::RouterRouteCreateParams = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -9168,17 +9000,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::RouterRouteUpdateParams = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -9305,16 +9130,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::VpcSubnetCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -9391,16 +9210,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::VpcSubnetUpdate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -9515,16 +9328,10 @@ impl Cli { pub async fn execute_policy_update(&self, matches: &clap::ArgMatches) { let mut request = self.client.policy_update(); if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::SiloRolePolicy = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -9673,16 +9480,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::SshKeyCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -9845,17 +9646,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::CertificateCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10110,17 +9904,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::GlobalImageCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10219,16 +10006,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::IpPoolCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10281,16 +10062,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::IpPoolUpdate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10365,16 +10140,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::IpRange = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10399,16 +10168,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::IpRange = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10471,16 +10234,10 @@ impl Cli { pub async fn execute_ip_pool_service_range_add(&self, matches: &clap::ArgMatches) { let mut request = self.client.ip_pool_service_range_add(); if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::IpRange = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10501,16 +10258,10 @@ impl Cli { pub async fn execute_ip_pool_service_range_remove(&self, matches: &clap::ArgMatches) { let mut request = self.client.ip_pool_service_range_remove(); if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::IpRange = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10588,16 +10339,10 @@ impl Cli { pub async fn execute_system_policy_update(&self, matches: &clap::ArgMatches) { let mut request = self.client.system_policy_update(); if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::FleetRolePolicy = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10712,16 +10457,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::SiloCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10822,16 +10561,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::UserCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10884,16 +10617,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::UserPassword = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -10950,17 +10677,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::SamlIdentityProviderCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -11029,16 +10749,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::SiloRolePolicy = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -11279,16 +10993,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::DiskCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -11439,16 +11147,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::InstanceCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -11583,16 +11285,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::DiskPath = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -11629,16 +11325,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::DiskPath = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -11675,16 +11365,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::InstanceMigrate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -11895,17 +11579,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::OrganizationCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -11958,17 +11635,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::OrganizationUpdate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -12033,17 +11703,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::OrganizationRolePolicy = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -12110,16 +11773,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::ProjectCreate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -12180,16 +11837,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::ProjectUpdate = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -12266,17 +11917,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::ProjectRolePolicy = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -12397,17 +12041,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::SystemUpdateStart = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } diff --git a/progenitor-impl/tests/output/propolis-server-cli.out b/progenitor-impl/tests/output/propolis-server-cli.out index 373221cf..ac8ea68d 100644 --- a/progenitor-impl/tests/output/propolis-server-cli.out +++ b/progenitor-impl/tests/output/propolis-server-cli.out @@ -205,17 +205,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::InstanceEnsureRequest = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -267,17 +260,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::InstanceMigrateStatusRequest = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -314,17 +300,10 @@ impl Cli { pub async fn execute_instance_state_put(&self, matches: &clap::ArgMatches) { let mut request = self.client.instance_state_put(); if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::InstanceStateRequested = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } @@ -349,17 +328,10 @@ impl Cli { } if let Some(value) = matches.get_one::("json-body") { - use std::io::Read; - let body_input = match value.as_str() { - "-" => { - let mut buf = Vec::new(); - std::io::stdin().read_to_end(&mut buf).unwrap(); - buf - } - file => std::fs::read(&file).unwrap(), + let body_value: types::InstanceStateMonitorRequest = match value.as_str() { + "-" => serde_json::from_reader(std::io::stdin()).unwrap(), + file => serde_json::from_reader(std::fs::File::open(&file).unwrap()).unwrap(), }; - let body_value = - serde_json::from_slice::(&body_input).unwrap(); request = request.body(body_value); } From c3dee486225d793f3af94f0e434415c8ce0a7696 Mon Sep 17 00:00:00 2001 From: augustuswm Date: Wed, 1 Nov 2023 16:19:53 -0500 Subject: [PATCH 3/4] Attempt to compile generated sdk and clis --- Cargo.lock | 28 ++++++++++++ Cargo.toml | 1 + progenitor-impl/Cargo.toml | 10 +++++ progenitor-impl/tests/test_compilation.rs | 46 +++++++++++++++++++ test-progenitor-compilation/Cargo.toml | 24 ++++++++++ test-progenitor-compilation/src/lib.rs | 54 +++++++++++++++++++++++ 6 files changed, 163 insertions(+) create mode 100644 progenitor-impl/tests/test_compilation.rs create mode 100644 test-progenitor-compilation/Cargo.toml create mode 100644 test-progenitor-compilation/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 0b594b40..3881b6a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1432,8 +1432,12 @@ dependencies = [ name = "progenitor-impl" version = "0.4.0" dependencies = [ + "base64", + "chrono", + "clap", "dropshot", "expectorate", + "futures", "getopts", "heck", "http", @@ -1441,17 +1445,23 @@ dependencies = [ "indexmap 2.0.2", "openapiv3", "proc-macro2", + "progenitor-client", "quote", + "rand", "regex", + "regress", + "reqwest", "rustfmt-wrapper", "schemars", "serde", "serde_json", "serde_yaml", "syn 2.0.38", + "test-progenitor-compilation", "thiserror", "typify", "unicode-ident", + "uuid", ] [[package]] @@ -2141,6 +2151,24 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "test-progenitor-compilation" +version = "0.1.0" +dependencies = [ + "dropshot", + "expectorate", + "http", + "hyper", + "openapiv3", + "proc-macro2", + "progenitor-impl", + "quote", + "schemars", + "serde_json", + "serde_yaml", + "syn 2.0.38", +] + [[package]] name = "thiserror" version = "1.0.49" diff --git a/Cargo.toml b/Cargo.toml index 03c1dfce..7a5de166 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ members = [ "progenitor-client", "progenitor-impl", "progenitor-macro", + "test-progenitor-compilation", ] resolver = "2" diff --git a/progenitor-impl/Cargo.toml b/progenitor-impl/Cargo.toml index 89a850c5..9db40ab0 100644 --- a/progenitor-impl/Cargo.toml +++ b/progenitor-impl/Cargo.toml @@ -27,10 +27,20 @@ typify = { git = "https://github.com/oxidecomputer/typify" } unicode-ident = "1.0.12" [dev-dependencies] +base64 = "0.21" +clap = { version = "4.4", features = ["derive", "string", "env"] } +chrono = { version = "0.4", features = ["serde"] } dropshot = { git = "https://github.com/oxidecomputer/dropshot", default-features = false } expectorate = "1.1" +futures = "0.3.27" http = "0.2.9" hyper = "0.14.27" +progenitor-client = { path = "../progenitor-client" } +rand = "0.8" +regress = "0.7.1" +reqwest = { version = "0.11.22", features = ["json", "stream"] } rustfmt-wrapper = "0.2.0" serde_yaml = "0.9" serde_json = "1.0.107" +test-progenitor-compilation = { path = "../test-progenitor-compilation" } +uuid = { version = "1.4", features = ["serde", "v4"] } diff --git a/progenitor-impl/tests/test_compilation.rs b/progenitor-impl/tests/test_compilation.rs new file mode 100644 index 00000000..0f1a822c --- /dev/null +++ b/progenitor-impl/tests/test_compilation.rs @@ -0,0 +1,46 @@ +// Copyright 2022 Oxide Computer Company + +use test_progenitor_compilation::cli_tokens; + +#[test] +fn test_keeper_compilation() { + cli_tokens!("keeper.json"); +} + +#[test] +fn test_buildomat_compilation() { + cli_tokens!("buildomat.json"); +} + +#[test] +fn test_nexus_compilation() { + cli_tokens!("nexus.json"); +} + +#[test] +fn test_propolis_server_compilation() { + cli_tokens!("propolis-server.json"); +} + +#[test] +fn test_param_override_compilation() { + cli_tokens!("param-overrides.json"); +} + +#[test] +fn test_yaml_compilation() { + cli_tokens!("param-overrides.yaml"); +} + +#[test] +fn test_param_collision_compilation() { + cli_tokens!("param-collision.json"); +} + +// TODO this file is full of inconsistencies and incorrectly specified types. +// It's an interesting test to consider whether we try to do our best to +// interpret the intent or just fail. +// #[test] +// fn test_github() { +// cli_tokens!("api.github.com.json"); +// } diff --git a/test-progenitor-compilation/Cargo.toml b/test-progenitor-compilation/Cargo.toml new file mode 100644 index 00000000..be90359b --- /dev/null +++ b/test-progenitor-compilation/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "test-progenitor-compilation" +version = "0.1.0" +edition = "2021" +license = "MPL-2.0" +description = "An OpenAPI client generator - compilation test macro" +repository = "https://github.com/oxidecomputer/progenitor.git" + +[lib] +proc-macro = true + +[dependencies] +dropshot = { git = "https://github.com/oxidecomputer/dropshot", default-features = false } +expectorate = "1.1" +http = "0.2.9" +hyper = "0.14.27" +openapiv3 = "1.0.3" +proc-macro2 = "1.0" +progenitor-impl = { path = "../progenitor-impl" } +quote = "1.0" +schemars = { version = "0.8.12", features = ["chrono", "uuid1"] } +serde_yaml = "0.9" +serde_json = "1.0.107" +syn = { version = "2.0", features = ["parsing"] } diff --git a/test-progenitor-compilation/src/lib.rs b/test-progenitor-compilation/src/lib.rs new file mode 100644 index 00000000..e79d8dd1 --- /dev/null +++ b/test-progenitor-compilation/src/lib.rs @@ -0,0 +1,54 @@ +// Copyright 2022 Oxide Computer Company + +extern crate proc_macro; + +use openapiv3::OpenAPI; +use proc_macro::TokenStream; +use progenitor_impl::{Generator, GenerationSettings, InterfaceStyle, TagStyle}; +use quote::quote; +use std::{fs::File, path::{Path, PathBuf}}; + +#[proc_macro] +pub fn cli_tokens(item: TokenStream) -> TokenStream { + let arg = item.to_string().replace("\"", ""); + let mut in_path = PathBuf::from("sample_openapi"); + in_path.push(arg); + + let spec = load_api(in_path); + + let mut generator = Generator::new( + GenerationSettings::default() + .with_interface(InterfaceStyle::Builder) + .with_tag(TagStyle::Separate), + ); + + // Builder generation with tags. + let sdk = generator.generate_tokens(&spec).unwrap(); + + // CLI generation. + let cli = generator.cli(&spec, "sdk").unwrap(); + + quote! { + pub mod sdk { + #sdk + } + use sdk::*; + + #cli + }.into() +} + + +fn load_api

(p: P) -> OpenAPI +where + P: AsRef + std::clone::Clone + std::fmt::Debug, +{ + let mut f = File::open(p.clone()).unwrap(); + match serde_json::from_reader(f) { + Ok(json_value) => json_value, + _ => { + f = File::open(p).unwrap(); + serde_yaml::from_reader(f).unwrap() + } + } +} \ No newline at end of file From bfdce5c661f5e9e9f70845c9844db87dee40044c Mon Sep 17 00:00:00 2001 From: augustuswm Date: Wed, 1 Nov 2023 16:21:15 -0500 Subject: [PATCH 4/4] Fmt --- progenitor-impl/tests/test_compilation.rs | 2 +- test-progenitor-compilation/src/lib.rs | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/progenitor-impl/tests/test_compilation.rs b/progenitor-impl/tests/test_compilation.rs index 0f1a822c..e2324ca2 100644 --- a/progenitor-impl/tests/test_compilation.rs +++ b/progenitor-impl/tests/test_compilation.rs @@ -4,7 +4,7 @@ use test_progenitor_compilation::cli_tokens; #[test] fn test_keeper_compilation() { - cli_tokens!("keeper.json"); + cli_tokens!("keeper.json"); } #[test] diff --git a/test-progenitor-compilation/src/lib.rs b/test-progenitor-compilation/src/lib.rs index e79d8dd1..02ce2f1b 100644 --- a/test-progenitor-compilation/src/lib.rs +++ b/test-progenitor-compilation/src/lib.rs @@ -4,9 +4,14 @@ extern crate proc_macro; use openapiv3::OpenAPI; use proc_macro::TokenStream; -use progenitor_impl::{Generator, GenerationSettings, InterfaceStyle, TagStyle}; +use progenitor_impl::{ + GenerationSettings, Generator, InterfaceStyle, TagStyle, +}; use quote::quote; -use std::{fs::File, path::{Path, PathBuf}}; +use std::{ + fs::File, + path::{Path, PathBuf}, +}; #[proc_macro] pub fn cli_tokens(item: TokenStream) -> TokenStream { @@ -35,10 +40,10 @@ pub fn cli_tokens(item: TokenStream) -> TokenStream { use sdk::*; #cli - }.into() + } + .into() } - fn load_api

(p: P) -> OpenAPI where P: AsRef + std::clone::Clone + std::fmt::Debug, @@ -51,4 +56,4 @@ where serde_yaml::from_reader(f).unwrap() } } -} \ No newline at end of file +}