diff --git a/Cargo.lock b/Cargo.lock index bb2681c9..5cdefefd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1412,8 +1412,12 @@ dependencies = [ name = "progenitor-impl" version = "0.4.0" dependencies = [ + "base64", + "chrono", + "clap", "dropshot", "expectorate", + "futures", "getopts", "heck", "http", @@ -1421,17 +1425,23 @@ dependencies = [ "indexmap 2.1.0", "openapiv3", "proc-macro2", + "progenitor-client", "quote", + "rand", "regex", + "regress", + "reqwest", "rustfmt-wrapper", "schemars", "serde", "serde_json", "serde_yaml", "syn 2.0.41", + "test-progenitor-compilation", "thiserror", "typify", "unicode-ident", + "uuid", ] [[package]] @@ -2109,6 +2119,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.41", +] + [[package]] name = "thiserror" version = "1.0.50" 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 ed07a78b..1b00d700 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.1" serde_yaml = "0.9" serde_json = "1.0.108" +test-progenitor-compilation = { path = "../test-progenitor-compilation" } +uuid = { version = "1.6", features = ["serde", "v4"] } diff --git a/progenitor-impl/src/cli.rs b/progenitor-impl/src/cli.rs index e03067b2..dde45d41 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,14 +477,13 @@ 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(); - let body_value = - serde_json::from_str::<#body_type_ident>( - &body_txt, - ) - .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(), + }; + request = request.body(body_value); } } diff --git a/progenitor-impl/tests/output/buildomat-cli.out b/progenitor-impl/tests/output/buildomat-cli.out index 1292e679..bb062e7c 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,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -551,9 +571,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -611,9 +633,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -665,9 +689,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -715,9 +741,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -749,9 +777,11 @@ 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") { + 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(), + }; request = request.body(body_value); } diff --git a/progenitor-impl/tests/output/keeper-cli.out b/progenitor-impl/tests/output/keeper-cli.out index 69a5f07b..76d4593c 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,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -298,9 +312,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -324,9 +340,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -359,9 +377,11 @@ 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") { + 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(), + }; request = request.body(body_value); } diff --git a/progenitor-impl/tests/output/nexus-cli.out b/progenitor-impl/tests/output/nexus-cli.out index 6eacbc90..6cde3847 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,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -6451,9 +6624,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -6485,10 +6660,11 @@ 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(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + 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(), + }; request = request.body(body_value); } @@ -6540,9 +6716,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -6574,10 +6752,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -6695,9 +6874,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -6749,9 +6930,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -6815,10 +6998,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -6884,9 +7068,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -6946,9 +7132,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -7048,9 +7236,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -7227,9 +7417,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -7377,9 +7569,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -7513,9 +7707,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -7551,9 +7747,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -7617,9 +7815,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -7713,10 +7913,11 @@ 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(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + 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(), + }; request = request.body(body_value); } @@ -7796,10 +7997,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -8035,9 +8237,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -8115,9 +8319,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -8253,9 +8459,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -8323,9 +8531,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -8409,10 +8619,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -8494,9 +8705,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -8572,9 +8785,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -8696,10 +8911,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -8783,10 +8999,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -8912,9 +9129,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -8990,9 +9209,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -9106,9 +9327,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -9256,9 +9479,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -9420,9 +9645,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -9676,9 +9903,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -9776,9 +10005,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -9830,9 +10061,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -9906,9 +10139,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -9932,9 +10167,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -9996,9 +10233,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -10018,9 +10257,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -10097,9 +10338,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -10213,9 +10456,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -10315,9 +10560,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -10369,9 +10616,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -10427,10 +10676,11 @@ 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(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + 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(), + }; request = request.body(body_value); } @@ -10498,9 +10748,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -10740,9 +10992,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -10892,9 +11146,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -11028,9 +11284,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -11066,9 +11324,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -11104,9 +11364,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -11316,9 +11578,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -11370,9 +11634,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -11436,10 +11702,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -11505,9 +11772,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -11567,9 +11836,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -11645,9 +11916,11 @@ 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") { + 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(), + }; request = request.body(body_value); } @@ -11767,9 +12040,11 @@ 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") { + 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(), + }; 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 7d44ec6e..a4ddf7b0 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,11 @@ 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(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + 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(), + }; request = request.body(body_value); } @@ -246,10 +259,11 @@ 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(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + 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(), + }; request = request.body(body_value); } @@ -285,10 +299,11 @@ 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(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + 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(), + }; request = request.body(body_value); } @@ -312,10 +327,11 @@ 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(); - let body_value = - serde_json::from_str::(&body_txt).unwrap(); + if let Some(value) = matches.get_one::("json-body") { + 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(), + }; request = request.body(body_value); } diff --git a/progenitor-impl/tests/test_compilation.rs b/progenitor-impl/tests/test_compilation.rs new file mode 100644 index 00000000..e2324ca2 --- /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..1301fa27 --- /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 = "2.0.0" +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"] } \ No newline at end of file diff --git a/test-progenitor-compilation/src/lib.rs b/test-progenitor-compilation/src/lib.rs new file mode 100644 index 00000000..02ce2f1b --- /dev/null +++ b/test-progenitor-compilation/src/lib.rs @@ -0,0 +1,59 @@ +// Copyright 2022 Oxide Computer Company + +extern crate proc_macro; + +use openapiv3::OpenAPI; +use proc_macro::TokenStream; +use progenitor_impl::{ + GenerationSettings, Generator, 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() + } + } +}