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

Method execute

crates/chat-cli/src/cli/chat/cli/editor.rs:25–84  ·  view source on GitHub ↗
(self, session: &mut ChatSession)

Source from the content-addressed store, hash-verified

23
24impl EditorArgs {
25 pub async fn execute(self, session: &mut ChatSession) -> Result<ChatState, ChatError> {
26 let initial_text = if self.initial_text.is_empty() {
27 None
28 } else {
29 Some(self.initial_text.join(" "))
30 };
31
32 let content = match open_editor(initial_text) {
33 Ok(content) => content,
34 Err(err) => {
35 execute!(
36 session.stderr,
37 StyledText::error_fg(),
38 style::Print(format!("\nError opening editor: {}\n\n", err)),
39 StyledText::reset(),
40 )?;
41
42 return Ok(ChatState::PromptUser {
43 skip_printing_tools: true,
44 });
45 },
46 };
47
48 Ok(match content.trim().is_empty() {
49 true => {
50 execute!(
51 session.stderr,
52 StyledText::warning_fg(),
53 style::Print("\nEmpty content from editor, not submitting.\n\n"),
54 StyledText::reset(),
55 )?;
56
57 ChatState::PromptUser {
58 skip_printing_tools: true,
59 }
60 },
61 false => {
62 execute!(
63 session.stderr,
64 StyledText::success_fg(),
65 style::Print("\nContent loaded from editor. Submitting prompt...\n\n"),
66 StyledText::reset(),
67 )?;
68
69 // Display the content as if the user typed it
70 execute!(
71 session.stderr,
72 StyledText::reset_attributes(),
73 StyledText::emphasis_fg(),
74 style::Print("> "),
75 StyledText::reset_attributes(),
76 style::Print(&content),
77 style::Print("\n")
78 )?;
79
80 // Process the content as user input
81 ChatState::HandleInput { input: content }
82 },

Callers

nothing calls this directly

Calls 3

open_editorFunction · 0.85
joinMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected