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

Method handle_clear

crates/chat-cli/src/cli/chat/cli/knowledge.rs:366–417  ·  view source on GitHub ↗

Handle clear operation

(os: &Os, session: &mut ChatSession)

Source from the content-addressed store, hash-verified

364
365 /// Handle clear operation
366 async fn handle_clear(os: &Os, session: &mut ChatSession) -> OperationResult {
367 // Require confirmation
368 queue!(
369 session.stderr,
370 style::Print("⚠️ This action will remove all knowledge base entries.\n"),
371 style::Print("Clear the knowledge base? (y/N): ")
372 )
373 .unwrap();
374 session.stderr.flush().unwrap();
375
376 let mut input = String::new();
377 if std::io::stdin().read_line(&mut input).is_err() {
378 return OperationResult::Error("Failed to read input".to_string());
379 }
380
381 let input = input.trim().to_lowercase();
382 if input != "y" && input != "yes" {
383 return OperationResult::Info("Clear operation cancelled".to_string());
384 }
385
386 let agent = Self::get_agent(session);
387 let async_knowledge_store = match KnowledgeStore::get_async_instance(os, agent).await {
388 Ok(store) => store,
389 Err(e) => return OperationResult::Error(format!("Error accessing knowledge base directory: {}", e)),
390 };
391 let mut store = async_knowledge_store.lock().await;
392
393 // First, cancel any pending operations
394 queue!(
395 session.stderr,
396 style::Print("🛑 Cancelling any pending operations...\n")
397 )
398 .unwrap();
399 if let Err(e) = store.cancel_operation(None).await {
400 queue!(
401 session.stderr,
402 style::Print(&format!("⚠️ Warning: Failed to cancel operations: {}\n", e))
403 )
404 .unwrap();
405 }
406
407 // Now perform immediate synchronous clear
408 queue!(
409 session.stderr,
410 style::Print("🗑️ Clearing all knowledge base entries...\n")
411 )
412 .unwrap();
413 match store.clear_immediate().await {
414 Ok(message) => OperationResult::Success(message),
415 Err(e) => OperationResult::Error(format!("Failed to clear: {}", e)),
416 }
417 }
418
419 /// Format status data for display (UI rendering responsibility)
420 fn format_status_display(status: &SystemStatus) -> String {

Callers

nothing calls this directly

Calls 6

read_lineMethod · 0.80
to_stringMethod · 0.80
clear_immediateMethod · 0.80
ErrorEnum · 0.50
flushMethod · 0.45
cancel_operationMethod · 0.45

Tested by

no test coverage detected