This commit is contained in:
94
.cli_memory/commands/recording.py
Normal file
94
.cli_memory/commands/recording.py
Normal file
@@ -0,0 +1,94 @@
|
||||
import click
|
||||
from rich import print as rprint
|
||||
from rich.panel import Panel
|
||||
from rich.table import Table
|
||||
|
||||
from ..config import Config
|
||||
from ..database import Database
|
||||
from ..recorder import CommandRecorder
|
||||
from ..project import ProjectDetector
|
||||
|
||||
|
||||
@click.group()
|
||||
def record():
|
||||
"""Record and manage command recordings."""
|
||||
pass
|
||||
|
||||
|
||||
@record.command()
|
||||
@click.option("--project", "-p", help="Project name or path")
|
||||
@click.option("--tag", "-t", multiple=True, help="Tags for this recording")
|
||||
def start(project, tag):
|
||||
"""Start an interactive recording session."""
|
||||
rprint(Panel.fit("[yellow]Starting recording session...[/yellow]", title="Record"))
|
||||
rprint("[cyan]Type 'exit' to stop recording[/cyan]")
|
||||
|
||||
detector = ProjectDetector()
|
||||
proj = detector.detect(project)
|
||||
if proj:
|
||||
rprint(f"[green]Detected project: {proj.name}[/green]")
|
||||
|
||||
recorder = CommandRecorder()
|
||||
|
||||
commands = []
|
||||
try:
|
||||
while True:
|
||||
cmd_input = input("cm-record> ").strip()
|
||||
if cmd_input.lower() in ("exit", "quit", "q"):
|
||||
break
|
||||
if cmd_input:
|
||||
commands.append(cmd_input)
|
||||
except (EOFError, KeyboardInterrupt):
|
||||
pass
|
||||
|
||||
if commands:
|
||||
rprint(f"[green]Recorded {len(commands)} commands[/green]")
|
||||
else:
|
||||
rprint("[yellow]No commands recorded[/yellow]")
|
||||
|
||||
|
||||
@record.command()
|
||||
@click.argument("command")
|
||||
@click.option("--project", "-p", help="Project path")
|
||||
def single(command, project):
|
||||
"""Record a single command."""
|
||||
recorder = CommandRecorder()
|
||||
detector = ProjectDetector()
|
||||
proj = detector.detect(project)
|
||||
|
||||
cmd = recorder.record_command(command, project_id=proj.id if proj else None)
|
||||
|
||||
db = Database()
|
||||
db.create_command(cmd)
|
||||
db.close()
|
||||
|
||||
rprint(f"[green]Recorded: {command}[/green]")
|
||||
|
||||
|
||||
@record.command()
|
||||
@click.option("--limit", "-l", default=20, help="Number of recent commands to show")
|
||||
def recent(limit):
|
||||
"""Show recent recorded commands."""
|
||||
db = Database()
|
||||
commands = db.get_commands(limit=limit)
|
||||
db.close()
|
||||
|
||||
if not commands:
|
||||
rprint("[yellow]No commands recorded yet[/yellow]")
|
||||
return
|
||||
|
||||
table = Table(title="Recent Commands")
|
||||
table.add_column("ID", style="cyan")
|
||||
table.add_column("Command", style="magenta")
|
||||
table.add_column("Type", style="green")
|
||||
table.add_column("Timestamp", style="yellow")
|
||||
|
||||
for cmd in commands[:limit]:
|
||||
table.add_row(
|
||||
str(cmd.id),
|
||||
cmd.command[:50] + "..." if len(cmd.command) > 50 else cmd.command,
|
||||
cmd.command_type.value,
|
||||
cmd.timestamp.strftime("%Y-%m-%d %H:%M"),
|
||||
)
|
||||
|
||||
rprint(Panel(table, title="Recent Commands"))
|
||||
Reference in New Issue
Block a user