MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / invoke

Method invoke

crates/chat-cli/src/cli/chat/tools/use_aws.rs:53–115  ·  view source on GitHub ↗
(&self, os: &Os, _updates: impl Write)

Source from the content-addressed store, hash-verified

51 }
52
53 pub async fn invoke(&self, os: &Os, _updates: impl Write) -> Result<InvokeOutput> {
54 let mut command = tokio::process::Command::new("aws");
55
56 // Set up environment variables with user agent metadata for CloudTrail tracking
57 let env_vars = env_vars_with_user_agent(os);
58
59 command.envs(env_vars).arg("--region").arg(&self.region);
60 if let Some(profile_name) = self.profile_name.as_deref() {
61 command.arg("--profile").arg(profile_name);
62 }
63 command.arg(&self.service_name).arg(&self.operation_name);
64 if let Some(parameters) = self.cli_parameters() {
65 for (name, val) in parameters {
66 command.arg(name);
67 if !val.is_empty() {
68 command.arg(val);
69 }
70 }
71 }
72 let output = command
73 .stdout(Stdio::piped())
74 .stderr(Stdio::piped())
75 .spawn()
76 .wrap_err_with(|| format!("Unable to spawn command '{:?}'", self))?
77 .wait_with_output()
78 .await
79 .wrap_err_with(|| format!("Unable to spawn command '{:?}'", self))?;
80 let status = output.status.code().unwrap_or(0).to_string();
81 let stdout = output.stdout.to_str_lossy();
82 let stderr = output.stderr.to_str_lossy();
83
84 let stdout = format!(
85 "{}{}",
86 &stdout[0..stdout.len().min(MAX_TOOL_RESPONSE_SIZE / 3)],
87 if stdout.len() > MAX_TOOL_RESPONSE_SIZE / 3 {
88 " ... truncated"
89 } else {
90 ""
91 }
92 );
93
94 let stderr = format!(
95 "{}{}",
96 &stderr[0..stderr.len().min(MAX_TOOL_RESPONSE_SIZE / 3)],
97 if stderr.len() > MAX_TOOL_RESPONSE_SIZE / 3 {
98 " ... truncated"
99 } else {
100 ""
101 }
102 );
103
104 if status.eq("0") {
105 Ok(InvokeOutput {
106 output: OutputKind::Json(serde_json::json!({
107 "exit_status": status,
108 "stdout": stdout,
109 "stderr": stderr.clone()
110 })),

Callers 1

test_aws_outputFunction · 0.45

Calls 9

cli_parametersMethod · 0.80
to_stringMethod · 0.80
eqMethod · 0.80
env_vars_with_user_agentFunction · 0.70
is_emptyMethod · 0.45
spawnMethod · 0.45
stderrMethod · 0.45
stdoutMethod · 0.45
codeMethod · 0.45

Tested by 1

test_aws_outputFunction · 0.36