(
os: &Os,
session: &mut ChatSession,
name: String,
content: Option<String>,
global: bool,
)
| 1446 | } |
| 1447 | |
| 1448 | async fn execute_create( |
| 1449 | os: &Os, |
| 1450 | session: &mut ChatSession, |
| 1451 | name: String, |
| 1452 | content: Option<String>, |
| 1453 | global: bool, |
| 1454 | ) -> Result<ChatState, ChatError> { |
| 1455 | // Create prompts instance and validate name |
| 1456 | let mut prompts = Prompts::new(&name, os).map_err(|e| ChatError::Custom(e.to_string().into()))?; |
| 1457 | |
| 1458 | if let Err(validation_error) = validate_prompt_name(&name) { |
| 1459 | queue!( |
| 1460 | session.stderr, |
| 1461 | style::Print("\n"), |
| 1462 | StyledText::error_fg(), |
| 1463 | style::Print("❌ Invalid prompt name: "), |
| 1464 | style::Print(validation_error), |
| 1465 | style::Print("\n"), |
| 1466 | StyledText::secondary_fg(), |
| 1467 | style::Print("Valid names contain only letters, numbers, hyphens, and underscores (1-50 characters)\n"), |
| 1468 | StyledText::reset(), |
| 1469 | )?; |
| 1470 | return Ok(ChatState::PromptUser { |
| 1471 | skip_printing_tools: true, |
| 1472 | }); |
| 1473 | } |
| 1474 | |
| 1475 | // Check if prompt already exists in target location |
| 1476 | let (local_exists, global_exists) = (prompts.local.exists(), prompts.global.exists()); |
| 1477 | let target_exists = if global { global_exists } else { local_exists }; |
| 1478 | |
| 1479 | if target_exists { |
| 1480 | let location = if global { "global" } else { "local" }; |
| 1481 | queue!( |
| 1482 | session.stderr, |
| 1483 | style::Print("\n"), |
| 1484 | StyledText::warning_fg(), |
| 1485 | style::Print("Prompt "), |
| 1486 | StyledText::brand_fg(), |
| 1487 | style::Print(&name), |
| 1488 | StyledText::warning_fg(), |
| 1489 | style::Print(" already exists in "), |
| 1490 | style::Print(location), |
| 1491 | style::Print(" directory. Use "), |
| 1492 | StyledText::brand_fg(), |
| 1493 | style::Print("/prompts edit "), |
| 1494 | style::Print(&name), |
| 1495 | if global { |
| 1496 | style::Print(" --global") |
| 1497 | } else { |
| 1498 | style::Print("") |
| 1499 | }, |
| 1500 | StyledText::warning_fg(), |
| 1501 | style::Print(" to modify it.\n"), |
| 1502 | StyledText::reset(), |
| 1503 | )?; |
| 1504 | return Ok(ChatState::PromptUser { |
| 1505 | skip_printing_tools: true, |
nothing calls this directly
no test coverage detected