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

Method execute

crates/chat-cli/src/cli/chat/cli/prompts.rs:599–839  ·  view source on GitHub ↗
(self, os: &Os, session: &mut ChatSession)

Source from the content-addressed store, hash-verified

597
598impl PromptsArgs {
599 pub async fn execute(self, os: &Os, session: &mut ChatSession) -> Result<ChatState, ChatError> {
600 let search_word = match &self.subcommand {
601 Some(PromptsSubcommand::List { search_word }) => search_word.clone(),
602 _ => None,
603 };
604
605 if let Some(subcommand) = self.subcommand {
606 if matches!(
607 subcommand,
608 PromptsSubcommand::Get { .. }
609 | PromptsSubcommand::Details { .. }
610 | PromptsSubcommand::Create { .. }
611 | PromptsSubcommand::Edit { .. }
612 | PromptsSubcommand::Remove { .. }
613 ) {
614 return subcommand.execute(os, session).await;
615 }
616 }
617
618 let terminal_width = session.terminal_width();
619 let prompts = session.conversation.tool_manager.list_prompts().await?;
620
621 // Get available prompt names
622 let prompt_names = Prompts::get_available_names(os).map_err(|e| ChatError::Custom(e.to_string().into()))?;
623
624 let mut longest_name = "";
625
626 // Update longest_name to include local prompts
627 for name in &prompt_names {
628 if name.contains(search_word.as_deref().unwrap_or("")) && name.len() > longest_name.len() {
629 longest_name = name;
630 }
631 }
632 let mut prompts_by_server: Vec<_> = prompts
633 .iter()
634 .fold(
635 HashMap::<&String, Vec<&PromptBundle>>::new(),
636 |mut acc, (prompt_name, bundles)| {
637 if prompt_name.contains(search_word.as_deref().unwrap_or("")) {
638 if prompt_name.len() > longest_name.len() {
639 longest_name = prompt_name.as_str();
640 }
641 for bundle in bundles {
642 acc.entry(&bundle.server_name)
643 .and_modify(|b| b.push(bundle))
644 .or_insert(vec![bundle]);
645 }
646 }
647 acc
648 },
649 )
650 .into_iter()
651 .collect();
652 prompts_by_server.sort_by_key(|(server_name, _)| server_name.as_str());
653
654 // Calculate positions for three-column layout: Prompt | Description | Arguments
655 let prompt_col_width = (UnicodeWidthStr::width(longest_name) + 4).max(20); // Min 20 chars for "Prompt"
656 let description_col_width = 41; // Fixed width for descriptions

Callers

nothing calls this directly

Calls 15

CustomClass · 0.85
format_descriptionFunction · 0.85
terminal_widthMethod · 0.80
to_stringMethod · 0.80
prompts_dirMethod · 0.80
globalMethod · 0.80
truncate_descriptionFunction · 0.70
cloneMethod · 0.45
list_promptsMethod · 0.45
lenMethod · 0.45
as_strMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected