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

Method execute

crates/chat-cli/src/cli/agent/root_command_args.rs:82–320  ·  view source on GitHub ↗
(self, os: &mut Os)

Source from the content-addressed store, hash-verified

80
81impl AgentArgs {
82 pub async fn execute(self, os: &mut Os) -> Result<ExitCode> {
83 let mut stderr = std::io::stderr();
84 let mcp_enabled = match os.client.is_mcp_enabled().await {
85 Ok(enabled) => enabled,
86 Err(err) => {
87 tracing::warn!(?err, "Failed to check MCP configuration, defaulting to enabled");
88 true
89 },
90 };
91 match self.cmd {
92 Some(AgentSubcommands::List) | None => {
93 let agents = Agents::load(os, None, true, &mut stderr, mcp_enabled).await.0;
94 let agent_with_path =
95 agents
96 .agents
97 .into_iter()
98 .fold(Vec::<(String, String)>::new(), |mut acc, (name, agent)| {
99 acc.push((
100 name,
101 agent
102 .path
103 .and_then(|p| p.parent().map(|p| p.to_string_lossy().to_string()))
104 .unwrap_or("**No path found**".to_string()),
105 ));
106 acc
107 });
108 let max_name_length = agent_with_path.iter().map(|(name, _)| name.len()).max().unwrap_or(0);
109 let output_str = agent_with_path
110 .into_iter()
111 .map(|(name, path)| format!("{name:<width$} {path}", width = max_name_length))
112 .collect::<Vec<_>>()
113 .join("\n");
114
115 writeln!(stderr, "{}", output_str)?;
116 },
117 Some(AgentSubcommands::Create { name, directory, from }) => {
118 let mut agents = Agents::load(os, None, true, &mut stderr, mcp_enabled).await.0;
119 let path_with_file_name = create_agent(os, &mut agents, name.clone(), directory, from).await?;
120
121 crate::util::editor::launch_editor(&path_with_file_name)?;
122
123 let Ok(content) = os.fs.read(&path_with_file_name).await else {
124 bail!(
125 "Post write validation failed. Error opening {}. Aborting",
126 path_with_file_name.display()
127 );
128 };
129 if let Err(e) = serde_json::from_slice::<Agent>(&content) {
130 bail!(
131 "Post write validation failed for agent '{name}' at path: {}. Malformed config detected: {e}",
132 path_with_file_name.display()
133 );
134 }
135
136 writeln!(
137 stderr,
138 "\n📁 Created agent {} '{}'\n",
139 name,

Callers

nothing calls this directly

Calls 14

create_agentFunction · 0.85
migrateFunction · 0.85
is_mcp_enabledMethod · 0.80
mapMethod · 0.80
to_stringMethod · 0.80
joinMethod · 0.80
readMethod · 0.80
switchMethod · 0.80
setMethod · 0.80
launch_editorFunction · 0.50
lenMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected