feat: render cli dry-run previews
This commit is contained in:
1 parent
14e406b3ba
commit
d9408fc09a
1 file changed
+66
-1
@@ -303,7 +303,72 @@ fn main() -> anyhow::Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn render_execution_preview(cli: &Cli) -> String {
|
fn render_execution_preview(cli: &Cli) -> String {
|
||||||
format!("DRY RUN {}", render_command_summary(cli))
|
let preview = execution_preview(
|
||||||
|
cli,
|
||||||
|
&execution_stub(&execution_contract(&plan_command(cli))),
|
||||||
|
);
|
||||||
|
|
||||||
|
match (cli.format, preview) {
|
||||||
|
(OutputFormat::Text, ExecutionPreview::SummaryOnly { command }) => {
|
||||||
|
format!("DRY RUN {}", command)
|
||||||
|
}
|
||||||
|
(
|
||||||
|
OutputFormat::Text,
|
||||||
|
ExecutionPreview::HttpPreview {
|
||||||
|
method,
|
||||||
|
url,
|
||||||
|
api_key_present,
|
||||||
|
..
|
||||||
|
},
|
||||||
|
) => format!(
|
||||||
|
"DRY RUN {} {} api_key_present={}",
|
||||||
|
method, url, api_key_present
|
||||||
|
),
|
||||||
|
(
|
||||||
|
OutputFormat::Text,
|
||||||
|
ExecutionPreview::LocalPreview {
|
||||||
|
action,
|
||||||
|
target,
|
||||||
|
effect,
|
||||||
|
},
|
||||||
|
) => format!("DRY RUN {} target={} effect={}", action, target, effect),
|
||||||
|
(OutputFormat::Json, ExecutionPreview::SummaryOnly { command }) => {
|
||||||
|
format!(r#"{{"kind":"summary","command":"{}"}}"#, command)
|
||||||
|
}
|
||||||
|
(
|
||||||
|
OutputFormat::Json,
|
||||||
|
ExecutionPreview::HttpPreview {
|
||||||
|
method,
|
||||||
|
url,
|
||||||
|
api_key_present,
|
||||||
|
body,
|
||||||
|
},
|
||||||
|
) => format!(
|
||||||
|
r#"{{"kind":"http","method":"{}","url":"{}","api_key_present":{},"body":{}}}"#,
|
||||||
|
method,
|
||||||
|
url,
|
||||||
|
api_key_present,
|
||||||
|
render_json_body(body.as_deref())
|
||||||
|
),
|
||||||
|
(
|
||||||
|
OutputFormat::Json,
|
||||||
|
ExecutionPreview::LocalPreview {
|
||||||
|
action,
|
||||||
|
target,
|
||||||
|
effect,
|
||||||
|
},
|
||||||
|
) => format!(
|
||||||
|
r#"{{"kind":"local","action":"{}","target":"{}","effect":"{}"}}"#,
|
||||||
|
action, target, effect
|
||||||
|
),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn render_json_body(body: Option<&str>) -> String {
|
||||||
|
match body {
|
||||||
|
Some(body) => format!(r#""{}""#, body),
|
||||||
|
None => "null".to_owned(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_command_summary(cli: &Cli) -> String {
|
fn render_command_summary(cli: &Cli) -> String {
|
||||||
|
|||||||
Reference in new issue
Block a user