Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions progenitor-impl/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ impl Generator {

let code = quote! {
use #crate_path::*;
use anyhow::Context as _;

pub struct Cli<T: CliConfig> {
client: Client,
Expand Down Expand Up @@ -510,12 +511,12 @@ impl Generator {
if let Some(value) =
matches.get_one::<std::path::PathBuf>("json-body")
{
let body_txt = std::fs::read_to_string(value).unwrap();
let body_txt = std::fs::read_to_string(value).with_context(|| format!("failed to read {}", value.display()))?;
let body_value =
serde_json::from_str::<#body_type_ident>(
&body_txt,
)
.unwrap();
.with_context(|| format!("failed to parse {}", value.display()))?;
request = request.body(body_value);
}
}
Expand Down
37 changes: 25 additions & 12 deletions progenitor-impl/tests/output/src/buildomat_cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::buildomat_builder::*;
use anyhow::Context as _;
pub struct Cli<T: CliConfig> {
client: Client,
config: T,
Expand Down Expand Up @@ -465,8 +466,10 @@ impl<T: CliConfig> Cli<T> {
}

if let Some(value) = matches.get_one::<std::path::PathBuf>("json-body") {
let body_txt = std::fs::read_to_string(value).unwrap();
let body_value = serde_json::from_str::<types::TaskSubmit>(&body_txt).unwrap();
let body_txt = std::fs::read_to_string(value)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_value = serde_json::from_str::<types::TaskSubmit>(&body_txt)
.with_context(|| format!("failed to parse {}", value.display()))?;
request = request.body(body_value);
}

Expand Down Expand Up @@ -569,8 +572,10 @@ impl<T: CliConfig> Cli<T> {
}

if let Some(value) = matches.get_one::<std::path::PathBuf>("json-body") {
let body_txt = std::fs::read_to_string(value).unwrap();
let body_value = serde_json::from_str::<types::UserCreate>(&body_txt).unwrap();
let body_txt = std::fs::read_to_string(value)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_value = serde_json::from_str::<types::UserCreate>(&body_txt)
.with_context(|| format!("failed to parse {}", value.display()))?;
request = request.body(body_value);
}

Expand Down Expand Up @@ -637,8 +642,10 @@ impl<T: CliConfig> Cli<T> {
}

if let Some(value) = matches.get_one::<std::path::PathBuf>("json-body") {
let body_txt = std::fs::read_to_string(value).unwrap();
let body_value = serde_json::from_str::<types::WorkerBootstrap>(&body_txt).unwrap();
let body_txt = std::fs::read_to_string(value)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_value = serde_json::from_str::<types::WorkerBootstrap>(&body_txt)
.with_context(|| format!("failed to parse {}", value.display()))?;
request = request.body(body_value);
}

Expand Down Expand Up @@ -695,8 +702,10 @@ impl<T: CliConfig> Cli<T> {
}

if let Some(value) = matches.get_one::<std::path::PathBuf>("json-body") {
let body_txt = std::fs::read_to_string(value).unwrap();
let body_value = serde_json::from_str::<types::WorkerAppendTask>(&body_txt).unwrap();
let body_txt = std::fs::read_to_string(value)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_value = serde_json::from_str::<types::WorkerAppendTask>(&body_txt)
.with_context(|| format!("failed to parse {}", value.display()))?;
request = request.body(body_value);
}

Expand Down Expand Up @@ -753,8 +762,10 @@ impl<T: CliConfig> Cli<T> {
}

if let Some(value) = matches.get_one::<std::path::PathBuf>("json-body") {
let body_txt = std::fs::read_to_string(value).unwrap();
let body_value = serde_json::from_str::<types::WorkerCompleteTask>(&body_txt).unwrap();
let body_txt = std::fs::read_to_string(value)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_value = serde_json::from_str::<types::WorkerCompleteTask>(&body_txt)
.with_context(|| format!("failed to parse {}", value.display()))?;
request = request.body(body_value);
}

Expand Down Expand Up @@ -791,8 +802,10 @@ impl<T: CliConfig> Cli<T> {
}

if let Some(value) = matches.get_one::<std::path::PathBuf>("json-body") {
let body_txt = std::fs::read_to_string(value).unwrap();
let body_value = serde_json::from_str::<types::WorkerAddOutput>(&body_txt).unwrap();
let body_txt = std::fs::read_to_string(value)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_value = serde_json::from_str::<types::WorkerAddOutput>(&body_txt)
.with_context(|| format!("failed to parse {}", value.display()))?;
request = request.body(body_value);
}

Expand Down
7 changes: 5 additions & 2 deletions progenitor-impl/tests/output/src/cli_gen_cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::cli_gen_builder::*;
use anyhow::Context as _;
pub struct Cli<T: CliConfig> {
client: Client,
config: T,
Expand Down Expand Up @@ -56,8 +57,10 @@ impl<T: CliConfig> Cli<T> {
}

if let Some(value) = matches.get_one::<std::path::PathBuf>("json-body") {
let body_txt = std::fs::read_to_string(value).unwrap();
let body_value = serde_json::from_str::<types::UnoBody>(&body_txt).unwrap();
let body_txt = std::fs::read_to_string(value)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_value = serde_json::from_str::<types::UnoBody>(&body_txt)
.with_context(|| format!("failed to parse {}", value.display()))?;
request = request.body(body_value);
}

Expand Down
25 changes: 17 additions & 8 deletions progenitor-impl/tests/output/src/keeper_cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::keeper_builder::*;
use anyhow::Context as _;
pub struct Cli<T: CliConfig> {
client: Client,
config: T,
Expand Down Expand Up @@ -216,8 +217,10 @@ impl<T: CliConfig> Cli<T> {
}

if let Some(value) = matches.get_one::<std::path::PathBuf>("json-body") {
let body_txt = std::fs::read_to_string(value).unwrap();
let body_value = serde_json::from_str::<types::EnrolBody>(&body_txt).unwrap();
let body_txt = std::fs::read_to_string(value)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_value = serde_json::from_str::<types::EnrolBody>(&body_txt)
.with_context(|| format!("failed to parse {}", value.display()))?;
request = request.body(body_value);
}

Expand Down Expand Up @@ -296,8 +299,10 @@ impl<T: CliConfig> Cli<T> {
}

if let Some(value) = matches.get_one::<std::path::PathBuf>("json-body") {
let body_txt = std::fs::read_to_string(value).unwrap();
let body_value = serde_json::from_str::<types::ReportFinishBody>(&body_txt).unwrap();
let body_txt = std::fs::read_to_string(value)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_value = serde_json::from_str::<types::ReportFinishBody>(&body_txt)
.with_context(|| format!("failed to parse {}", value.display()))?;
request = request.body(body_value);
}

Expand All @@ -322,8 +327,10 @@ impl<T: CliConfig> Cli<T> {
}

if let Some(value) = matches.get_one::<std::path::PathBuf>("json-body") {
let body_txt = std::fs::read_to_string(value).unwrap();
let body_value = serde_json::from_str::<types::ReportOutputBody>(&body_txt).unwrap();
let body_txt = std::fs::read_to_string(value)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_value = serde_json::from_str::<types::ReportOutputBody>(&body_txt)
.with_context(|| format!("failed to parse {}", value.display()))?;
request = request.body(body_value);
}

Expand Down Expand Up @@ -358,8 +365,10 @@ impl<T: CliConfig> Cli<T> {
}

if let Some(value) = matches.get_one::<std::path::PathBuf>("json-body") {
let body_txt = std::fs::read_to_string(value).unwrap();
let body_value = serde_json::from_str::<types::ReportStartBody>(&body_txt).unwrap();
let body_txt = std::fs::read_to_string(value)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_value = serde_json::from_str::<types::ReportStartBody>(&body_txt)
.with_context(|| format!("failed to parse {}", value.display()))?;
request = request.body(body_value);
}

Expand Down
Loading