diff --git a/Cargo.lock b/Cargo.lock index a3c101a7..62aed3ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -142,9 +142,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.83" +version = "0.1.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" +checksum = "e539d3fca749fcee5236ab05e93a52867dd549cc157c8cb7f99595f3cedffdb5" dependencies = [ "proc-macro2", "quote", @@ -938,12 +938,12 @@ dependencies = [ [[package]] name = "http-body-util" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" dependencies = [ "bytes", - "futures-util", + "futures-core", "http", "http-body", "pin-project-lite", @@ -1006,9 +1006,9 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.10" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df2dcfbe0677734ab2f3ffa7fa7bfd4706bfdc1ef393f2ee30184aed67e631b4" +checksum = "497bbc33a26fdd4af9ed9c70d63f61cf56a938375fbb32df34db9b1cd6d643f2" dependencies = [ "bytes", "futures-channel", @@ -1016,6 +1016,7 @@ dependencies = [ "http", "http-body", "hyper", + "libc", "pin-project-lite", "socket2", "tokio", @@ -1234,9 +1235,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.169" +version = "0.2.172" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" +checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" [[package]] name = "linux-raw-sys" @@ -1611,6 +1612,10 @@ dependencies = [ name = "progenitor-impl" version = "0.10.0" dependencies = [ + "anyhow", + "base64", + "chrono", + "clap", "dropshot", "expectorate", "futures", @@ -1622,7 +1627,9 @@ dependencies = [ "proc-macro2", "progenitor-client", "quote", + "rand", "regex", + "regress", "reqwest", "rustfmt-wrapper", "schemars", @@ -1631,10 +1638,12 @@ dependencies = [ "serde_json", "serde_yaml", "syn", + "test-progenitor-compilation", "thiserror 2.0.12", "tokio", "typify", "unicode-ident", + "uuid", ] [[package]] @@ -2030,9 +2039,9 @@ dependencies = [ [[package]] name = "serde_path_to_error" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6" +checksum = "59fab13f937fa393d08645bf3a84bdfe86e296747b506ada67bb15f10f218b2a" dependencies = [ "itoa", "serde", @@ -2040,9 +2049,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.7" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" dependencies = [ "serde", ] @@ -2185,12 +2194,12 @@ checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" -version = "0.5.5" +version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" +checksum = "4f5fd57c80058a56cf5c777ab8a126398ece8e442983605d280a44ce79d0edef" dependencies = [ "libc", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] @@ -2311,6 +2320,24 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683" +[[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", +] + [[package]] name = "thiserror" version = "1.0.69" @@ -2469,9 +2496,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.19" +version = "0.8.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +checksum = "05ae329d1f08c4d17a59bed7ff5b5a769d062e64a62d34a3261b219e62cd5aae" dependencies = [ "serde", "serde_spanned", @@ -2481,26 +2508,33 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.8" +version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +checksum = "3da5db5a963e24bc68be8b17b6fa82814bb22ee8660f192bb182771d498f09a3" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.22.20" +version = "0.22.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" +checksum = "310068873db2c5b3e7659d2cc35d21855dbafa50d1ce336397c666e3cb08137e" dependencies = [ "indexmap", "serde", "serde_spanned", "toml_datetime", + "toml_write", "winnow", ] +[[package]] +name = "toml_write" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfb942dfe1d8e29a7ee7fcbde5bd2b9a25fb89aa70caea2eba3bee836ff41076" + [[package]] name = "toolchain_find" version = "0.4.0" @@ -3152,9 +3186,9 @@ checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" [[package]] name = "winnow" -version = "0.6.18" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" +checksum = "d9fb597c990f03753e08d3c29efbfcf2019a003b4bf4ba19225c158e1549f0f3" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index f90a1922..866d777f 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 f4a3a9af..43694e82 100644 --- a/progenitor-impl/Cargo.toml +++ b/progenitor-impl/Cargo.toml @@ -24,14 +24,22 @@ typify = { workspace = true } unicode-ident = { workspace = true } [dev-dependencies] +anyhow = { workspace = true } +base64 = { workspace = true } +chrono = { workspace = true } +clap = { workspace = true } dropshot = { workspace = true } expectorate = { workspace = true } futures = { workspace = true } http = { workspace = true } hyper = { workspace = true } progenitor-client = { workspace = true } +rand = { workspace = true } +regress = { workspace = true } reqwest = { workspace = true } rustfmt-wrapper = { workspace = true } semver = { workspace = true } serde_yaml = { workspace = true } +test-progenitor-compilation = { path = "../test-progenitor-compilation" } tokio = { workspace = true } +uuid = { workspace = true } diff --git a/progenitor-impl/src/cli.rs b/progenitor-impl/src/cli.rs index 95dd4fe6..43c58253 100644 --- a/progenitor-impl/src/cli.rs +++ b/progenitor-impl/src/cli.rs @@ -465,7 +465,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( @@ -475,7 +475,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( @@ -501,14 +501,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 new file mode 100644 index 00000000..bb062e7c --- /dev/null +++ b/progenitor-impl/tests/output/buildomat-cli.out @@ -0,0 +1,1038 @@ +pub struct Cli { + client: sdk::Client, + over: T, +} + +impl Cli { + pub fn new(client: sdk::Client) -> Self { + Self { client, over: () } + } + + pub fn get_command(cmd: CliCommand) -> clap::Command { + match cmd { + CliCommand::ControlHold => Self::cli_control_hold(), + CliCommand::ControlResume => Self::cli_control_resume(), + CliCommand::TaskGet => Self::cli_task_get(), + CliCommand::TasksGet => Self::cli_tasks_get(), + CliCommand::TaskSubmit => Self::cli_task_submit(), + CliCommand::TaskEventsGet => Self::cli_task_events_get(), + CliCommand::TaskOutputsGet => Self::cli_task_outputs_get(), + CliCommand::TaskOutputDownload => Self::cli_task_output_download(), + CliCommand::UserCreate => Self::cli_user_create(), + CliCommand::Whoami => Self::cli_whoami(), + CliCommand::WhoamiPutName => Self::cli_whoami_put_name(), + CliCommand::WorkerBootstrap => Self::cli_worker_bootstrap(), + CliCommand::WorkerPing => Self::cli_worker_ping(), + CliCommand::WorkerTaskAppend => Self::cli_worker_task_append(), + CliCommand::WorkerTaskUploadChunk => Self::cli_worker_task_upload_chunk(), + CliCommand::WorkerTaskComplete => Self::cli_worker_task_complete(), + CliCommand::WorkerTaskAddOutput => Self::cli_worker_task_add_output(), + CliCommand::WorkersList => Self::cli_workers_list(), + CliCommand::WorkersRecycle => Self::cli_workers_recycle(), + } + } + + pub fn cli_control_hold() -> clap::Command { + clap::Command::new("") + } + + pub fn cli_control_resume() -> clap::Command { + clap::Command::new("") + } + + pub fn cli_task_get() -> clap::Command { + clap::Command::new("").arg( + clap::Arg::new("task") + .long("task") + .value_parser(clap::value_parser!(String)) + .required(true), + ) + } + + pub fn cli_tasks_get() -> clap::Command { + clap::Command::new("") + } + + pub fn cli_task_submit() -> clap::Command { + clap::Command::new("") + .arg( + clap::Arg::new("name") + .long("name") + .value_parser(clap::value_parser!(String)) + .required_unless_present("json-body"), + ) + .arg( + clap::Arg::new("script") + .long("script") + .value_parser(clap::value_parser!(String)) + .required_unless_present("json-body"), + ) + .arg( + clap::Arg::new("json-body") + .long("json-body") + .value_name("JSON-FILE") + .required(false) + .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") + .long("json-body-template") + .action(clap::ArgAction::SetTrue) + .help("XXX"), + ) + } + + pub fn cli_task_events_get() -> clap::Command { + clap::Command::new("") + .arg( + clap::Arg::new("minseq") + .long("minseq") + .value_parser(clap::value_parser!(u32)) + .required(false), + ) + .arg( + clap::Arg::new("task") + .long("task") + .value_parser(clap::value_parser!(String)) + .required(true), + ) + } + + pub fn cli_task_outputs_get() -> clap::Command { + clap::Command::new("").arg( + clap::Arg::new("task") + .long("task") + .value_parser(clap::value_parser!(String)) + .required(true), + ) + } + + pub fn cli_task_output_download() -> clap::Command { + clap::Command::new("") + .arg( + clap::Arg::new("output") + .long("output") + .value_parser(clap::value_parser!(String)) + .required(true), + ) + .arg( + clap::Arg::new("task") + .long("task") + .value_parser(clap::value_parser!(String)) + .required(true), + ) + } + + pub fn cli_user_create() -> clap::Command { + clap::Command::new("") + .arg( + clap::Arg::new("name") + .long("name") + .value_parser(clap::value_parser!(String)) + .required_unless_present("json-body"), + ) + .arg( + clap::Arg::new("json-body") + .long("json-body") + .value_name("JSON-FILE") + .required(false) + .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") + .long("json-body-template") + .action(clap::ArgAction::SetTrue) + .help("XXX"), + ) + } + + pub fn cli_whoami() -> clap::Command { + clap::Command::new("") + } + + pub fn cli_whoami_put_name() -> clap::Command { + clap::Command::new("") + } + + pub fn cli_worker_bootstrap() -> clap::Command { + clap::Command::new("") + .arg( + clap::Arg::new("bootstrap") + .long("bootstrap") + .value_parser(clap::value_parser!(String)) + .required_unless_present("json-body"), + ) + .arg( + clap::Arg::new("token") + .long("token") + .value_parser(clap::value_parser!(String)) + .required_unless_present("json-body"), + ) + .arg( + clap::Arg::new("json-body") + .long("json-body") + .value_name("JSON-FILE") + .required(false) + .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") + .long("json-body-template") + .action(clap::ArgAction::SetTrue) + .help("XXX"), + ) + } + + pub fn cli_worker_ping() -> clap::Command { + clap::Command::new("") + } + + pub fn cli_worker_task_append() -> clap::Command { + clap::Command::new("") + .arg( + clap::Arg::new("payload") + .long("payload") + .value_parser(clap::value_parser!(String)) + .required_unless_present("json-body"), + ) + .arg( + clap::Arg::new("stream") + .long("stream") + .value_parser(clap::value_parser!(String)) + .required_unless_present("json-body"), + ) + .arg( + clap::Arg::new("task") + .long("task") + .value_parser(clap::value_parser!(String)) + .required(true), + ) + .arg( + clap::Arg::new("time") + .long("time") + .value_parser(clap::value_parser!(chrono::DateTime)) + .required_unless_present("json-body"), + ) + .arg( + clap::Arg::new("json-body") + .long("json-body") + .value_name("JSON-FILE") + .required(false) + .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") + .long("json-body-template") + .action(clap::ArgAction::SetTrue) + .help("XXX"), + ) + } + + pub fn cli_worker_task_upload_chunk() -> clap::Command { + clap::Command::new("").arg( + clap::Arg::new("task") + .long("task") + .value_parser(clap::value_parser!(String)) + .required(true), + ) + } + + pub fn cli_worker_task_complete() -> clap::Command { + clap::Command::new("") + .arg( + clap::Arg::new("failed") + .long("failed") + .value_parser(clap::value_parser!(bool)) + .required_unless_present("json-body"), + ) + .arg( + clap::Arg::new("task") + .long("task") + .value_parser(clap::value_parser!(String)) + .required(true), + ) + .arg( + clap::Arg::new("json-body") + .long("json-body") + .value_name("JSON-FILE") + .required(false) + .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") + .long("json-body-template") + .action(clap::ArgAction::SetTrue) + .help("XXX"), + ) + } + + pub fn cli_worker_task_add_output() -> clap::Command { + clap::Command::new("") + .arg( + clap::Arg::new("path") + .long("path") + .value_parser(clap::value_parser!(String)) + .required_unless_present("json-body"), + ) + .arg( + clap::Arg::new("size") + .long("size") + .value_parser(clap::value_parser!(i64)) + .required_unless_present("json-body"), + ) + .arg( + clap::Arg::new("task") + .long("task") + .value_parser(clap::value_parser!(String)) + .required(true), + ) + .arg( + clap::Arg::new("json-body") + .long("json-body") + .value_name("JSON-FILE") + .required(true) + .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") + .long("json-body-template") + .action(clap::ArgAction::SetTrue) + .help("XXX"), + ) + } + + pub fn cli_workers_list() -> clap::Command { + clap::Command::new("") + } + + pub fn cli_workers_recycle() -> clap::Command { + clap::Command::new("") + } +} + +impl Cli { + pub fn new_with_override(client: sdk::Client, over: T) -> Self { + Self { client, over } + } + + pub async fn execute(&self, cmd: CliCommand, matches: &clap::ArgMatches) { + match cmd { + CliCommand::ControlHold => { + self.execute_control_hold(matches).await; + } + CliCommand::ControlResume => { + self.execute_control_resume(matches).await; + } + CliCommand::TaskGet => { + self.execute_task_get(matches).await; + } + CliCommand::TasksGet => { + self.execute_tasks_get(matches).await; + } + CliCommand::TaskSubmit => { + self.execute_task_submit(matches).await; + } + CliCommand::TaskEventsGet => { + self.execute_task_events_get(matches).await; + } + CliCommand::TaskOutputsGet => { + self.execute_task_outputs_get(matches).await; + } + CliCommand::TaskOutputDownload => { + self.execute_task_output_download(matches).await; + } + CliCommand::UserCreate => { + self.execute_user_create(matches).await; + } + CliCommand::Whoami => { + self.execute_whoami(matches).await; + } + CliCommand::WhoamiPutName => { + self.execute_whoami_put_name(matches).await; + } + CliCommand::WorkerBootstrap => { + self.execute_worker_bootstrap(matches).await; + } + CliCommand::WorkerPing => { + self.execute_worker_ping(matches).await; + } + CliCommand::WorkerTaskAppend => { + self.execute_worker_task_append(matches).await; + } + CliCommand::WorkerTaskUploadChunk => { + self.execute_worker_task_upload_chunk(matches).await; + } + CliCommand::WorkerTaskComplete => { + self.execute_worker_task_complete(matches).await; + } + CliCommand::WorkerTaskAddOutput => { + self.execute_worker_task_add_output(matches).await; + } + CliCommand::WorkersList => { + self.execute_workers_list(matches).await; + } + CliCommand::WorkersRecycle => { + self.execute_workers_recycle(matches).await; + } + } + } + + pub async fn execute_control_hold(&self, matches: &clap::ArgMatches) { + let mut request = self.client.control_hold(); + self.over + .execute_control_hold(matches, &mut request) + .unwrap(); + let result = request.send().await; + match result { + Ok(r) => { + println!("success\n{:#?}", r) + } + Err(r) => { + println!("success\n{:#?}", r) + } + } + } + + pub async fn execute_control_resume(&self, matches: &clap::ArgMatches) { + let mut request = self.client.control_resume(); + self.over + .execute_control_resume(matches, &mut request) + .unwrap(); + let result = request.send().await; + match result { + Ok(r) => { + println!("success\n{:#?}", r) + } + Err(r) => { + println!("success\n{:#?}", r) + } + } + } + + pub async fn execute_task_get(&self, matches: &clap::ArgMatches) { + let mut request = self.client.task_get(); + if let Some(value) = matches.get_one::("task") { + request = request.task(value.clone()); + } + + self.over.execute_task_get(matches, &mut request).unwrap(); + let result = request.send().await; + match result { + Ok(r) => { + println!("success\n{:#?}", r) + } + Err(r) => { + println!("success\n{:#?}", r) + } + } + } + + pub async fn execute_tasks_get(&self, matches: &clap::ArgMatches) { + let mut request = self.client.tasks_get(); + self.over.execute_tasks_get(matches, &mut request).unwrap(); + let result = request.send().await; + match result { + Ok(r) => { + println!("success\n{:#?}", r) + } + Err(r) => { + println!("success\n{:#?}", r) + } + } + } + + pub async fn execute_task_submit(&self, matches: &clap::ArgMatches) { + let mut request = self.client.task_submit(); + if let Some(value) = matches.get_one::("name") { + request = request.body_map(|body| body.name(value.clone())) + } + + if let Some(value) = matches.get_one::("script") { + request = request.body_map(|body| body.script(value.clone())) + } + + 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); + } + + self.over + .execute_task_submit(matches, &mut request) + .unwrap(); + let result = request.send().await; + match result { + Ok(r) => { + println!("success\n{:#?}", r) + } + Err(r) => { + println!("success\n{:#?}", r) + } + } + } + + pub async fn execute_task_events_get(&self, matches: &clap::ArgMatches) { + let mut request = self.client.task_events_get(); + if let Some(value) = matches.get_one::("minseq") { + request = request.minseq(value.clone()); + } + + if let Some(value) = matches.get_one::("task") { + request = request.task(value.clone()); + } + + self.over + .execute_task_events_get(matches, &mut request) + .unwrap(); + let result = request.send().await; + match result { + Ok(r) => { + println!("success\n{:#?}", r) + } + Err(r) => { + println!("success\n{:#?}", r) + } + } + } + + pub async fn execute_task_outputs_get(&self, matches: &clap::ArgMatches) { + let mut request = self.client.task_outputs_get(); + if let Some(value) = matches.get_one::("task") { + request = request.task(value.clone()); + } + + self.over + .execute_task_outputs_get(matches, &mut request) + .unwrap(); + let result = request.send().await; + match result { + Ok(r) => { + println!("success\n{:#?}", r) + } + Err(r) => { + println!("success\n{:#?}", r) + } + } + } + + pub async fn execute_task_output_download(&self, matches: &clap::ArgMatches) { + let mut request = self.client.task_output_download(); + if let Some(value) = matches.get_one::("output") { + request = request.output(value.clone()); + } + + if let Some(value) = matches.get_one::("task") { + request = request.task(value.clone()); + } + + self.over + .execute_task_output_download(matches, &mut request) + .unwrap(); + let result = request.send().await; + match result { + Ok(r) => { + todo!() + } + Err(r) => { + println!("success\n{:#?}", r) + } + } + } + + pub async fn execute_user_create(&self, matches: &clap::ArgMatches) { + let mut request = self.client.user_create(); + if let Some(value) = matches.get_one::("name") { + request = request.body_map(|body| body.name(value.clone())) + } + + 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); + } + + self.over + .execute_user_create(matches, &mut request) + .unwrap(); + let result = request.send().await; + match result { + Ok(r) => { + println!("success\n{:#?}", r) + } + Err(r) => { + println!("success\n{:#?}", r) + } + } + } + + pub async fn execute_whoami(&self, matches: &clap::ArgMatches) { + let mut request = self.client.whoami(); + self.over.execute_whoami(matches, &mut request).unwrap(); + let result = request.send().await; + match result { + Ok(r) => { + println!("success\n{:#?}", r) + } + Err(r) => { + println!("success\n{:#?}", r) + } + } + } + + pub async fn execute_whoami_put_name(&self, matches: &clap::ArgMatches) { + let mut request = self.client.whoami_put_name(); + self.over + .execute_whoami_put_name(matches, &mut request) + .unwrap(); + let result = request.send().await; + match result { + Ok(r) => { + println!("success\n{:#?}", r) + } + Err(r) => { + println!("success\n{:#?}", r) + } + } + } + + pub async fn execute_worker_bootstrap(&self, matches: &clap::ArgMatches) { + let mut request = self.client.worker_bootstrap(); + if let Some(value) = matches.get_one::("bootstrap") { + request = request.body_map(|body| body.bootstrap(value.clone())) + } + + if let Some(value) = matches.get_one::("token") { + request = request.body_map(|body| body.token(value.clone())) + } + + 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); + } + + self.over + .execute_worker_bootstrap(matches, &mut request) + .unwrap(); + let result = request.send().await; + match result { + Ok(r) => { + println!("success\n{:#?}", r) + } + Err(r) => { + println!("success\n{:#?}", r) + } + } + } + + pub async fn execute_worker_ping(&self, matches: &clap::ArgMatches) { + let mut request = self.client.worker_ping(); + self.over + .execute_worker_ping(matches, &mut request) + .unwrap(); + let result = request.send().await; + match result { + Ok(r) => { + println!("success\n{:#?}", r) + } + Err(r) => { + println!("success\n{:#?}", r) + } + } + } + + pub async fn execute_worker_task_append(&self, matches: &clap::ArgMatches) { + let mut request = self.client.worker_task_append(); + if let Some(value) = matches.get_one::("payload") { + request = request.body_map(|body| body.payload(value.clone())) + } + + if let Some(value) = matches.get_one::("stream") { + request = request.body_map(|body| body.stream(value.clone())) + } + + if let Some(value) = matches.get_one::("task") { + request = request.task(value.clone()); + } + + if let Some(value) = matches.get_one::>("time") { + request = request.body_map(|body| body.time(value.clone())) + } + + 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); + } + + self.over + .execute_worker_task_append(matches, &mut request) + .unwrap(); + let result = request.send().await; + match result { + Ok(r) => { + println!("success\n{:#?}", r) + } + Err(r) => { + println!("success\n{:#?}", r) + } + } + } + + pub async fn execute_worker_task_upload_chunk(&self, matches: &clap::ArgMatches) { + let mut request = self.client.worker_task_upload_chunk(); + if let Some(value) = matches.get_one::("task") { + request = request.task(value.clone()); + } + + self.over + .execute_worker_task_upload_chunk(matches, &mut request) + .unwrap(); + let result = request.send().await; + match result { + Ok(r) => { + println!("success\n{:#?}", r) + } + Err(r) => { + println!("success\n{:#?}", r) + } + } + } + + pub async fn execute_worker_task_complete(&self, matches: &clap::ArgMatches) { + let mut request = self.client.worker_task_complete(); + if let Some(value) = matches.get_one::("failed") { + request = request.body_map(|body| body.failed(value.clone())) + } + + if let Some(value) = matches.get_one::("task") { + request = request.task(value.clone()); + } + + 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); + } + + self.over + .execute_worker_task_complete(matches, &mut request) + .unwrap(); + let result = request.send().await; + match result { + Ok(r) => { + println!("success\n{:#?}", r) + } + Err(r) => { + println!("success\n{:#?}", r) + } + } + } + + pub async fn execute_worker_task_add_output(&self, matches: &clap::ArgMatches) { + let mut request = self.client.worker_task_add_output(); + if let Some(value) = matches.get_one::("path") { + request = request.body_map(|body| body.path(value.clone())) + } + + if let Some(value) = matches.get_one::("size") { + request = request.body_map(|body| body.size(value.clone())) + } + + if let Some(value) = matches.get_one::("task") { + request = request.task(value.clone()); + } + + 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); + } + + self.over + .execute_worker_task_add_output(matches, &mut request) + .unwrap(); + let result = request.send().await; + match result { + Ok(r) => { + println!("success\n{:#?}", r) + } + Err(r) => { + println!("success\n{:#?}", r) + } + } + } + + pub async fn execute_workers_list(&self, matches: &clap::ArgMatches) { + let mut request = self.client.workers_list(); + self.over + .execute_workers_list(matches, &mut request) + .unwrap(); + let result = request.send().await; + match result { + Ok(r) => { + println!("success\n{:#?}", r) + } + Err(r) => { + println!("success\n{:#?}", r) + } + } + } + + pub async fn execute_workers_recycle(&self, matches: &clap::ArgMatches) { + let mut request = self.client.workers_recycle(); + self.over + .execute_workers_recycle(matches, &mut request) + .unwrap(); + let result = request.send().await; + match result { + Ok(r) => { + println!("success\n{:#?}", r) + } + Err(r) => { + println!("success\n{:#?}", r) + } + } + } +} + +pub trait CliOverride { + fn execute_control_hold( + &self, + matches: &clap::ArgMatches, + request: &mut builder::ControlHold, + ) -> Result<(), String> { + Ok(()) + } + + fn execute_control_resume( + &self, + matches: &clap::ArgMatches, + request: &mut builder::ControlResume, + ) -> Result<(), String> { + Ok(()) + } + + fn execute_task_get( + &self, + matches: &clap::ArgMatches, + request: &mut builder::TaskGet, + ) -> Result<(), String> { + Ok(()) + } + + fn execute_tasks_get( + &self, + matches: &clap::ArgMatches, + request: &mut builder::TasksGet, + ) -> Result<(), String> { + Ok(()) + } + + fn execute_task_submit( + &self, + matches: &clap::ArgMatches, + request: &mut builder::TaskSubmit, + ) -> Result<(), String> { + Ok(()) + } + + fn execute_task_events_get( + &self, + matches: &clap::ArgMatches, + request: &mut builder::TaskEventsGet, + ) -> Result<(), String> { + Ok(()) + } + + fn execute_task_outputs_get( + &self, + matches: &clap::ArgMatches, + request: &mut builder::TaskOutputsGet, + ) -> Result<(), String> { + Ok(()) + } + + fn execute_task_output_download( + &self, + matches: &clap::ArgMatches, + request: &mut builder::TaskOutputDownload, + ) -> Result<(), String> { + Ok(()) + } + + fn execute_user_create( + &self, + matches: &clap::ArgMatches, + request: &mut builder::UserCreate, + ) -> Result<(), String> { + Ok(()) + } + + fn execute_whoami( + &self, + matches: &clap::ArgMatches, + request: &mut builder::Whoami, + ) -> Result<(), String> { + Ok(()) + } + + fn execute_whoami_put_name( + &self, + matches: &clap::ArgMatches, + request: &mut builder::WhoamiPutName, + ) -> Result<(), String> { + Ok(()) + } + + fn execute_worker_bootstrap( + &self, + matches: &clap::ArgMatches, + request: &mut builder::WorkerBootstrap, + ) -> Result<(), String> { + Ok(()) + } + + fn execute_worker_ping( + &self, + matches: &clap::ArgMatches, + request: &mut builder::WorkerPing, + ) -> Result<(), String> { + Ok(()) + } + + fn execute_worker_task_append( + &self, + matches: &clap::ArgMatches, + request: &mut builder::WorkerTaskAppend, + ) -> Result<(), String> { + Ok(()) + } + + fn execute_worker_task_upload_chunk( + &self, + matches: &clap::ArgMatches, + request: &mut builder::WorkerTaskUploadChunk, + ) -> Result<(), String> { + Ok(()) + } + + fn execute_worker_task_complete( + &self, + matches: &clap::ArgMatches, + request: &mut builder::WorkerTaskComplete, + ) -> Result<(), String> { + Ok(()) + } + + fn execute_worker_task_add_output( + &self, + matches: &clap::ArgMatches, + request: &mut builder::WorkerTaskAddOutput, + ) -> Result<(), String> { + Ok(()) + } + + fn execute_workers_list( + &self, + matches: &clap::ArgMatches, + request: &mut builder::WorkersList, + ) -> Result<(), String> { + Ok(()) + } + + fn execute_workers_recycle( + &self, + matches: &clap::ArgMatches, + request: &mut builder::WorkersRecycle, + ) -> Result<(), String> { + Ok(()) + } +} + +impl CliOverride for () {} +#[derive(Copy, Clone, Debug)] +pub enum CliCommand { + ControlHold, + ControlResume, + TaskGet, + TasksGet, + TaskSubmit, + TaskEventsGet, + TaskOutputsGet, + TaskOutputDownload, + UserCreate, + Whoami, + WhoamiPutName, + WorkerBootstrap, + WorkerPing, + WorkerTaskAppend, + WorkerTaskUploadChunk, + WorkerTaskComplete, + WorkerTaskAddOutput, + WorkersList, + WorkersRecycle, +} + +impl CliCommand { + pub fn iter() -> impl Iterator { + vec![ + CliCommand::ControlHold, + CliCommand::ControlResume, + CliCommand::TaskGet, + CliCommand::TasksGet, + CliCommand::TaskSubmit, + CliCommand::TaskEventsGet, + CliCommand::TaskOutputsGet, + CliCommand::TaskOutputDownload, + CliCommand::UserCreate, + CliCommand::Whoami, + CliCommand::WhoamiPutName, + CliCommand::WorkerBootstrap, + CliCommand::WorkerPing, + CliCommand::WorkerTaskAppend, + CliCommand::WorkerTaskUploadChunk, + CliCommand::WorkerTaskComplete, + CliCommand::WorkerTaskAddOutput, + CliCommand::WorkersList, + CliCommand::WorkersRecycle, + ] + .into_iter() + } +} diff --git a/progenitor-impl/tests/output/src/keeper_cli.rs b/progenitor-impl/tests/output/src/keeper_cli.rs index 78b770b5..4bfb89eb 100644 --- a/progenitor-impl/tests/output/src/keeper_cli.rs +++ b/progenitor-impl/tests/output/src/keeper_cli.rs @@ -47,7 +47,10 @@ impl Cli { .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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), ) .arg( ::clap::Arg::new("json-body-template") @@ -111,8 +114,13 @@ 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!(std::path::PathBuf)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -136,8 +144,13 @@ 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!(std::path::PathBuf)) + .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 +188,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -215,9 +233,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); } @@ -295,9 +315,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); } @@ -321,9 +343,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); } @@ -357,9 +381,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/src/nexus_cli.rs b/progenitor-impl/tests/output/src/nexus_cli.rs index ee529962..bae88e97 100644 --- a/progenitor-impl/tests/output/src/nexus_cli.rs +++ b/progenitor-impl/tests/output/src/nexus_cli.rs @@ -355,8 +355,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -385,8 +390,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -427,8 +437,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -479,8 +494,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -515,8 +535,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -614,8 +639,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -666,8 +696,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -719,8 +754,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -791,8 +831,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -857,8 +902,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -968,8 +1018,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -1165,8 +1220,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -1336,8 +1396,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -1469,8 +1534,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -1513,8 +1583,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -1580,8 +1655,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -1695,8 +1775,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -1795,8 +1880,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -2036,8 +2126,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -2125,8 +2220,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -2272,8 +2372,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -2350,8 +2455,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -2433,8 +2543,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -2523,8 +2638,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -2607,8 +2727,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -2739,8 +2864,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -2835,8 +2965,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -2983,8 +3118,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -3067,8 +3207,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -3166,8 +3311,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -3279,8 +3429,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -3410,8 +3565,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -3619,8 +3779,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -3707,8 +3872,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -3755,8 +3925,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -3810,8 +3985,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -3835,8 +4015,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -3871,8 +4056,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -3890,8 +4080,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -3970,8 +4165,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -4093,8 +4293,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -4182,8 +4387,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -4239,8 +4449,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -4326,8 +4541,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -4383,8 +4603,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -4589,8 +4814,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -4751,8 +4981,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -4883,8 +5118,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -4926,8 +5166,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -4969,8 +5214,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -5174,8 +5424,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -5222,8 +5477,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -5269,8 +5529,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -5337,8 +5602,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -5397,8 +5667,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -5462,8 +5737,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -5548,8 +5828,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -6148,9 +6433,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); } @@ -6176,9 +6463,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); } @@ -6214,10 +6503,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); } @@ -6275,9 +6565,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); } @@ -6309,10 +6601,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); } @@ -6448,9 +6741,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); } @@ -6510,9 +6805,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); } @@ -6588,10 +6885,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); } @@ -6663,9 +6961,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); } @@ -6725,9 +7025,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); } @@ -6834,9 +7136,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); } @@ -7035,9 +7339,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); } @@ -7195,9 +7501,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); } @@ -7346,9 +7654,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); } @@ -7388,9 +7698,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); } @@ -7462,9 +7774,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); } @@ -7573,10 +7887,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); } @@ -7664,10 +7979,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); } @@ -7924,9 +8240,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); } @@ -8013,9 +8331,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); } @@ -8161,9 +8481,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); } @@ -8235,9 +8557,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); } @@ -8332,10 +8656,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); } @@ -8430,9 +8755,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); } @@ -8515,9 +8842,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); } @@ -8657,10 +8986,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); } @@ -8752,10 +9082,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); } @@ -8898,9 +9229,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); } @@ -8983,9 +9316,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); } @@ -9115,9 +9450,11 @@ impl Cli { pub async fn execute_policy_update(&self, matches: &::clap::ArgMatches) -> anyhow::Result<()> { 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); } @@ -9297,9 +9634,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); } @@ -9494,9 +9833,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); } @@ -9810,9 +10151,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); } @@ -9924,9 +10267,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); } @@ -9978,9 +10323,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); } @@ -10067,9 +10414,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); } @@ -10097,9 +10446,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); } @@ -10179,9 +10530,11 @@ impl Cli { matches: &::clap::ArgMatches, ) -> anyhow::Result<()> { 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); } @@ -10205,9 +10558,11 @@ impl Cli { matches: &::clap::ArgMatches, ) -> anyhow::Result<()> { 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); } @@ -10295,9 +10650,11 @@ impl Cli { matches: &::clap::ArgMatches, ) -> anyhow::Result<()> { 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); } @@ -10428,9 +10785,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); } @@ -10546,9 +10905,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); } @@ -10608,9 +10969,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); } @@ -10670,10 +11033,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); } @@ -10753,9 +11117,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); } @@ -11041,9 +11407,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); } @@ -11205,9 +11573,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); } @@ -11362,9 +11732,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); } @@ -11404,9 +11776,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); } @@ -11446,9 +11820,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); } @@ -11690,9 +12066,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); } @@ -11752,9 +12130,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); } @@ -11830,10 +12210,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); } @@ -11911,9 +12292,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); } @@ -11980,9 +12363,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); } @@ -12070,9 +12455,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); } @@ -12226,9 +12613,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/src/propolis_server_cli.rs b/progenitor-impl/tests/output/src/propolis_server_cli.rs index b5034ff4..8b9c70bc 100644 --- a/progenitor-impl/tests/output/src/propolis_server_cli.rs +++ b/progenitor-impl/tests/output/src/propolis_server_cli.rs @@ -40,8 +40,13 @@ 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!(std::path::PathBuf)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -81,8 +86,13 @@ 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!(std::path::PathBuf)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -103,8 +113,13 @@ 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!(std::path::PathBuf)) + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -127,8 +142,13 @@ 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."), + .help( + "Path to a file that contains the full json body (use \"-\" to read from \ + standard input).", + ), + ) .arg( ::clap::Arg::new("json-body-template") @@ -184,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); } @@ -242,10 +263,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); } @@ -286,10 +308,11 @@ impl Cli { matches: &::clap::ArgMatches, ) -> anyhow::Result<()> { 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); } @@ -317,10 +340,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..9fc6fa9b --- /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 = { workspace = true } +expectorate = { workspace = true } +http = { workspace = true } +hyper = { workspace = true } +openapiv3 = { workspace = true } +proc-macro2 = { workspace = true } +progenitor-impl = { workspace = true } +quote = { workspace = true } +schemars = { workspace = true } +serde_yaml = { workspace = true } +serde_json = { workspace = true } +syn = { workspace = true } diff --git a/test-progenitor-compilation/src/lib.rs b/test-progenitor-compilation/src/lib.rs new file mode 100644 index 00000000..3e6b029f --- /dev/null +++ b/test-progenitor-compilation/src/lib.rs @@ -0,0 +1,58 @@ +// 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) + .with_derive("schemars::JsonSchema"), + ); + + // 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() + } + } +}