Skip to content
Open
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
11 changes: 9 additions & 2 deletions progenitor-impl/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ impl Generator {
CliBodyArg::Optional => Some(false),
})
.map(|required| {
let help = "Path to a file that contains the full json body.";
let help =
"Path to a file that contains the full json body, or '-' to read from stdin.";

quote! {
.arg(
Expand Down Expand Up @@ -511,7 +512,13 @@ impl Generator {
if let Some(value) =
matches.get_one::<std::path::PathBuf>("json-body")
{
let body_txt = std::fs::read_to_string(value).with_context(|| format!("failed to read {}", value.display()))?;
let body_txt = if value.as_os_str() == "-" {
let mut buf = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut buf).context("failed to read from stdin")?;
buf
} else {
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,
Expand Down
96 changes: 78 additions & 18 deletions progenitor-impl/tests/output/src/buildomat_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ impl<T: CliConfig> Cli<T> {
.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, or '-' to read from \
stdin.",
),
)
.arg(
::clap::Arg::new("json-body-template")
Expand Down Expand Up @@ -148,7 +151,10 @@ impl<T: CliConfig> Cli<T> {
.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, or '-' to read from \
stdin.",
),
)
.arg(
::clap::Arg::new("json-body-template")
Expand Down Expand Up @@ -186,7 +192,10 @@ impl<T: CliConfig> Cli<T> {
.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, or '-' to read from \
stdin.",
),
)
.arg(
::clap::Arg::new("json-body-template")
Expand Down Expand Up @@ -234,7 +243,10 @@ impl<T: CliConfig> Cli<T> {
.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, or '-' to read from \
stdin.",
),
)
.arg(
::clap::Arg::new("json-body-template")
Expand Down Expand Up @@ -273,7 +285,10 @@ impl<T: CliConfig> Cli<T> {
.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, or '-' to read from \
stdin.",
),
)
.arg(
::clap::Arg::new("json-body-template")
Expand Down Expand Up @@ -309,7 +324,10 @@ impl<T: CliConfig> Cli<T> {
.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, or '-' to read from \
stdin.",
),
)
.arg(
::clap::Arg::new("json-body-template")
Expand Down Expand Up @@ -466,8 +484,15 @@ 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)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_txt = if value.as_os_str() == "-" {
let mut buf = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut buf)
.context("failed to read from stdin")?;
buf
} else {
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 @@ -572,8 +597,15 @@ 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)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_txt = if value.as_os_str() == "-" {
let mut buf = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut buf)
.context("failed to read from stdin")?;
buf
} else {
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 @@ -642,8 +674,15 @@ 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)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_txt = if value.as_os_str() == "-" {
let mut buf = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut buf)
.context("failed to read from stdin")?;
buf
} else {
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 @@ -702,8 +741,15 @@ 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)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_txt = if value.as_os_str() == "-" {
let mut buf = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut buf)
.context("failed to read from stdin")?;
buf
} else {
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 @@ -762,8 +808,15 @@ 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)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_txt = if value.as_os_str() == "-" {
let mut buf = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut buf)
.context("failed to read from stdin")?;
buf
} else {
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 @@ -802,8 +855,15 @@ 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)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_txt = if value.as_os_str() == "-" {
let mut buf = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut buf)
.context("failed to read from stdin")?;
buf
} else {
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
16 changes: 13 additions & 3 deletions progenitor-impl/tests/output/src/cli_gen_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ impl<T: CliConfig> Cli<T> {
.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, or '-' to read from \
stdin.",
),
)
.arg(
::clap::Arg::new("json-body-template")
Expand All @@ -57,8 +60,15 @@ 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)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_txt = if value.as_os_str() == "-" {
let mut buf = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut buf)
.context("failed to read from stdin")?;
buf
} else {
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
64 changes: 52 additions & 12 deletions progenitor-impl/tests/output/src/keeper_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ impl<T: CliConfig> Cli<T> {
.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, or '-' to read from \
stdin.",
),
)
.arg(
::clap::Arg::new("json-body-template")
Expand Down Expand Up @@ -113,7 +116,10 @@ impl<T: CliConfig> Cli<T> {
.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, or '-' to read from \
stdin.",
),
)
.arg(
::clap::Arg::new("json-body-template")
Expand All @@ -138,7 +144,10 @@ impl<T: CliConfig> Cli<T> {
.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, or '-' to read from \
stdin.",
),
)
.arg(
::clap::Arg::new("json-body-template")
Expand Down Expand Up @@ -177,7 +186,10 @@ impl<T: CliConfig> Cli<T> {
.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, or '-' to read from \
stdin.",
),
)
.arg(
::clap::Arg::new("json-body-template")
Expand Down Expand Up @@ -217,8 +229,15 @@ 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)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_txt = if value.as_os_str() == "-" {
let mut buf = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut buf)
.context("failed to read from stdin")?;
buf
} else {
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 @@ -299,8 +318,15 @@ 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)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_txt = if value.as_os_str() == "-" {
let mut buf = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut buf)
.context("failed to read from stdin")?;
buf
} else {
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 @@ -327,8 +353,15 @@ 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)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_txt = if value.as_os_str() == "-" {
let mut buf = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut buf)
.context("failed to read from stdin")?;
buf
} else {
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 @@ -365,8 +398,15 @@ 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)
.with_context(|| format!("failed to read {}", value.display()))?;
let body_txt = if value.as_os_str() == "-" {
let mut buf = String::new();
std::io::Read::read_to_string(&mut std::io::stdin(), &mut buf)
.context("failed to read from stdin")?;
buf
} else {
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
Loading