From e95a9593be24ec78bf57df551a4c54cabba8914f Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sat, 31 Jan 2026 10:28:09 +0000 Subject: [PATCH] feat: add CLI commands for export and suggestions --- cli_memory/commands/export.py | 98 +++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 cli_memory/commands/export.py diff --git a/cli_memory/commands/export.py b/cli_memory/commands/export.py new file mode 100644 index 0000000..284cbdf --- /dev/null +++ b/cli_memory/commands/export.py @@ -0,0 +1,98 @@ +import os +import json +import yaml +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 ..history import HistoryManager + + +@click.group() +def export(): + """Export data.""" + pass + + +@export.command() +@click.option("--output", "-o", default="commands.json", help="Output file") +def commands(output): + """Export commands to file.""" + db = Database() + history = HistoryManager(db=db) + + commands = db.get_commands(limit=10000) + data = [c.to_dict() for c in commands] + + db.close() + + if output.endswith(".json"): + with open(output, "w") as f: + json.dump(data, f, indent=2, default=str) + else: + with open(output, "w") as f: + yaml.dump(data, f) + + rprint(f"[green]Exported {len(commands)} commands to {output}[/green]") + + +@export.command() +@click.option("--output", "-o", default="workflows.yaml", help="Output file") +def workflows(output): + """Export workflows to file.""" + db = Database() + workflows = db.get_all_workflows() + data = [w.to_dict() for w in workflows] + + db.close() + + if output.endswith(".json"): + with open(output, "w") as f: + json.dump(data, f, indent=2, default=str) + else: + with open(output, "w") as f: + yaml.dump(data, f) + + rprint(f"[green]Exported {len(workflows)} workflows to {output}[/green]") + + +@export.command() +@click.option("--output", "-o", default="backup.json", help="Output file") +def all(output): + """Export all data.""" + db = Database() + history = HistoryManager(db=db) + + data_str = history.export_history(format="json" if output.endswith(".json") else "yaml") + + with open(output, "w") as f: + f.write(data_str) + + db.close() + + rprint(f"[green]Exported all data to {output}[/green]") + + +@export.command() +def scripts(): + """List generated scripts.""" + from ..generator import ScriptGenerator + + generator = ScriptGenerator() + scripts = generator.list_generated_scripts() + + if not scripts: + rprint("[yellow]No generated scripts found[/yellow]") + return + + table = Table(title="Generated Scripts") + table.add_column("Name", style="cyan") + table.add_column("Path", style="magenta") + + for s in scripts: + table.add_row(s["name"], s["path"]) + + rprint(Panel(table, title=f"{len(scripts)} Scripts"))