Initial upload: Local LLM Prompt Manager CLI tool
This commit is contained in:
70
src/commands/tag.py
Normal file
70
src/commands/tag.py
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
"""Tag management CLI commands."""
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
import click
|
||||||
|
|
||||||
|
from ..storage import PromptStorage
|
||||||
|
|
||||||
|
|
||||||
|
@click.group()
|
||||||
|
def tag_cmd():
|
||||||
|
"""Manage tags."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@tag_cmd.command("list")
|
||||||
|
@click.option("--dir", "prompt_dir", default=None, help="Prompt directory")
|
||||||
|
def list_tags(prompt_dir: Optional[str]):
|
||||||
|
"""List all tags."""
|
||||||
|
from rich.console import Console
|
||||||
|
from rich.table import Table
|
||||||
|
|
||||||
|
storage = PromptStorage(prompt_dir)
|
||||||
|
tags = storage.list_tags()
|
||||||
|
|
||||||
|
table = Table(title="Tags")
|
||||||
|
table.add_column("Tag", style="cyan")
|
||||||
|
table.add_column("Count", style="magenta")
|
||||||
|
table.add_column("Prompts", style="green")
|
||||||
|
|
||||||
|
for tag_name in tags:
|
||||||
|
tag = storage.get_tag(tag_name)
|
||||||
|
count = len(tag.prompts) if tag else 0
|
||||||
|
prompts_str = ", ".join(tag.prompts[:5]) + ("..." if len(tag.prompts) > 5 else "") if tag and tag.prompts else "-"
|
||||||
|
table.add_row(tag_name, str(count), prompts_str)
|
||||||
|
|
||||||
|
console = Console()
|
||||||
|
console.print(table)
|
||||||
|
|
||||||
|
|
||||||
|
@tag_cmd.command("add")
|
||||||
|
@click.argument("prompt_name")
|
||||||
|
@click.argument("tag")
|
||||||
|
@click.option("--dir", "prompt_dir", default=None, help="Prompt directory")
|
||||||
|
def add_tag(prompt_name: str, tag: str, prompt_dir: Optional[str]):
|
||||||
|
"""Add a tag to a prompt."""
|
||||||
|
storage = PromptStorage(prompt_dir)
|
||||||
|
|
||||||
|
if not storage.prompt_exists(prompt_name):
|
||||||
|
click.echo(f"Error: Prompt '{prompt_name}' not found", err=True)
|
||||||
|
return
|
||||||
|
|
||||||
|
storage.add_tag_to_prompt(prompt_name, tag)
|
||||||
|
click.echo(f"Added tag '{tag}' to prompt '{prompt_name}'")
|
||||||
|
|
||||||
|
|
||||||
|
@tag_cmd.command("remove")
|
||||||
|
@click.argument("prompt_name")
|
||||||
|
@click.argument("tag")
|
||||||
|
@click.option("--dir", "prompt_dir", default=None, help="Prompt directory")
|
||||||
|
def remove_tag(prompt_name: str, tag: str, prompt_dir: Optional[str]):
|
||||||
|
"""Remove a tag from a prompt."""
|
||||||
|
storage = PromptStorage(prompt_dir)
|
||||||
|
|
||||||
|
result = storage.remove_tag_from_prompt(prompt_name, tag)
|
||||||
|
|
||||||
|
if result:
|
||||||
|
click.echo(f"Removed tag '{tag}' from prompt '{prompt_name}'")
|
||||||
|
else:
|
||||||
|
click.echo(f"Error: Tag '{tag}' not found on prompt '{prompt_name}'", err=True)
|
||||||
Reference in New Issue
Block a user