aperture_cli/cli/
legacy_execute.rs1use crate::cache::models::CachedSpec;
8use crate::cli::OutputFormat;
9use crate::config::models::GlobalConfig;
10use crate::engine::executor::RetryContext;
11use crate::error::Error;
12use crate::response_cache::CacheConfig;
13use clap::ArgMatches;
14
15#[allow(clippy::too_many_arguments)]
22#[allow(clippy::missing_panics_doc)]
23pub async fn execute_request(
24 spec: &CachedSpec,
25 matches: &ArgMatches,
26 base_url: Option<&str>,
27 dry_run: bool,
28 idempotency_key: Option<&str>,
29 global_config: Option<&GlobalConfig>,
30 output_format: &OutputFormat,
31 jq_filter: Option<&str>,
32 cache_config: Option<&CacheConfig>,
33 capture_output: bool,
34 retry_context: Option<&RetryContext>,
35) -> Result<Option<String>, Error> {
36 use crate::cli::translate;
37 use crate::invocation::ExecutionContext;
38
39 if translate::has_show_examples_flag(matches) {
45 let operation_id = translate::matches_to_operation_id(spec, matches)?;
46 let operation = spec
47 .commands
48 .iter()
49 .find(|cmd| cmd.operation_id == operation_id)
50 .ok_or_else(|| Error::spec_not_found(&spec.name))?;
51 crate::cli::render::render_examples(operation);
52 return Ok(None);
53 }
54
55 let call = translate::matches_to_operation_call(spec, matches)?;
57
58 let ctx = ExecutionContext {
60 dry_run,
61 idempotency_key: idempotency_key.map(String::from),
62 cache_config: cache_config.cloned(),
63 retry_context: retry_context.cloned(),
64 base_url: base_url.map(String::from),
65 global_config: global_config.cloned(),
66 server_var_args: translate::extract_server_var_args(matches),
67 auto_paginate: false,
68 };
69
70 let result = crate::engine::executor::execute(spec, call, ctx).await?;
72
73 if capture_output {
75 crate::cli::render::render_result_to_string(&result, output_format, jq_filter)
76 } else {
77 crate::cli::render::render_result(&result, output_format, jq_filter)?;
78 Ok(None)
79 }
80}