Skip to content

Commit f29fbcc

Browse files
James Zhuclaude
andcommitted
Add interactive input support to cam prompt add command
- Add multi-line interactive input mode when no file or piped input provided - Users can enter prompt content interactively and finish with Ctrl+C - Updated command help and examples to reflect new functionality - Maintains backward compatibility with existing file and stdin input methods 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d859a74 commit f29fbcc

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

code_assistant_manager/cli/prompts_commands.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
"""Simplified CLI commands for prompt management."""
2-
31
import logging
42
import sys
53
from pathlib import Path
@@ -86,12 +84,12 @@ def add_prompt(
8684
file: Optional[Path] = typer.Option(None, "--file", "-f", help="Read content from file"),
8785
default: bool = typer.Option(False, "--default", help="Set as default prompt"),
8886
):
89-
"""Add a new prompt from file or stdin.
90-
87+
"""Add a new prompt from file, stdin, or interactive input.
88+
9189
Examples:
9290
cam prompt add my-prompt -f prompt.md
9391
cat prompt.md | cam prompt add my-prompt
94-
echo "Be helpful" | cam prompt add simple-prompt
92+
cam prompt add my-prompt # Interactive mode
9593
"""
9694
manager = _get_manager()
9795

@@ -101,7 +99,7 @@ def add_prompt(
10199
typer.echo(f"Error: Prompt with name '{name}' already exists. Use a different name or remove it first.")
102100
raise typer.Exit(1)
103101

104-
# Read content from file or stdin
102+
# Read content from file, stdin, or interactive input
105103
if file:
106104
if not file.exists():
107105
typer.echo(f"Error: File not found: {file}")
@@ -111,10 +109,17 @@ def add_prompt(
111109
# Read from stdin (piped input)
112110
content = sys.stdin.read()
113111
else:
114-
typer.echo("Error: Provide content via --file or pipe to stdin")
115-
typer.echo(" Example: cam prompt add my-prompt -f prompt.md")
116-
typer.echo(" Example: cat prompt.md | cam prompt add my-prompt")
117-
raise typer.Exit(1)
112+
# Interactive input mode
113+
typer.echo() # Enter a newline as requested
114+
typer.echo("Enter prompt content (press Ctrl+C when finished):")
115+
lines = []
116+
try:
117+
while True:
118+
line = input()
119+
lines.append(line)
120+
except KeyboardInterrupt:
121+
typer.echo("\n") # New line after Ctrl+C
122+
content = "\n".join(lines)
118123

119124
if not content.strip():
120125
typer.echo("Error: Content cannot be empty")

0 commit comments

Comments
 (0)