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

Method execute

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

Source from the content-addressed store, hash-verified

67
68impl TodoSubcommand {
69 pub async fn execute(self, os: &mut Os, session: &mut ChatSession) -> Result<ChatState, ChatError> {
70 // Check if todo lists are enabled
71 if !TodoList::is_enabled(os) {
72 execute!(
73 session.stderr,
74 StyledText::error_fg(),
75 style::Print("Todo lists are disabled. Enable them with: q settings chat.enableTodoList true\n"),
76 StyledText::reset(),
77 )?;
78 return Ok(ChatState::PromptUser {
79 skip_printing_tools: true,
80 });
81 }
82 TodoListState::init_dir(os)
83 .await
84 .map_err(|e| ChatError::Custom(format!("Could not create todos directory: {e}").into()))?;
85 match self {
86 Self::ClearFinished => {
87 let (todos, errors) = match get_all_todos(os).await {
88 Ok(res) => res,
89 Err(e) => return Err(ChatError::Custom(format!("Could not get to-do lists: {e}").into())),
90 };
91 let mut cleared_one = false;
92
93 for todo_status in todos.iter() {
94 if todo_status.tasks.iter().all(|b| b.completed) {
95 match delete_todo(os, &todo_status.id).await {
96 Ok(_) => cleared_one = true,
97 Err(e) => {
98 return Err(ChatError::Custom(format!("Could not delete to-do list: {e}").into()));
99 },
100 };
101 }
102 }
103 if cleared_one {
104 execute!(
105 session.stderr,
106 style::Print("✔ Cleared finished to-do lists!\n".green())
107 )?;
108 } else {
109 execute!(session.stderr, style::Print("No finished to-do lists to clear!\n"))?;
110 }
111 if !errors.is_empty() {
112 execute!(
113 session.stderr,
114 style::Print(format!("* Failed to get {} todo list(s)\n", errors.len()).dark_grey())
115 )?;
116 }
117 },
118 Self::Resume => match Self::get_descriptions_and_statuses(os).await {
119 Ok(entries) => {
120 if entries.is_empty() {
121 execute!(session.stderr, style::Print("No to-do lists to resume!\n"),)?;
122 } else if let Some(index) = fuzzy_select_todos(&entries, "Select a to-do list to resume:") {
123 if index < entries.len() {
124 execute!(
125 session.stderr,
126 style::Print(format!(

Callers

nothing calls this directly

Calls 8

CustomClass · 0.85
get_all_todosFunction · 0.85
delete_todoFunction · 0.85
fuzzy_select_todosFunction · 0.85
resume_todo_requestMethod · 0.80
display_listMethod · 0.80
is_emptyMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected