Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions llm_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def register_commands(cli):
@click.option("-m", "--model", default=None, help="Specify the model to use")
@click.option("-s", "--system", help="Custom system prompt")
@click.option("--key", help="API key to use")
def cmd(args, model, system, key):
@click.option("-p", "--print-only", is_flag=True, help="Print command instead of putting in interactive prompt")
def cmd(args, model, system, key, print_only):
"""Generate and execute commands in your shell"""
from llm.cli import get_default_model
prompt = " ".join(args)
Expand All @@ -30,7 +31,10 @@ def cmd(args, model, system, key):
if model_obj.needs_key:
model_obj.key = llm.get_key(key, model_obj.needs_key, model_obj.key_env_var)
result = model_obj.prompt(prompt, system=system or SYSTEM_PROMPT)
interactive_exec(str(result))
if print_only:
print(str(result).strip())
else:
interactive_exec(str(result))

def interactive_exec(command):
session = PromptSession(lexer=PygmentsLexer(BashLexer))
Expand Down
12 changes: 11 additions & 1 deletion tests/test_cmd.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
from llm.plugins import pm
from llm.plugins import load_plugins, pm
import click


def test_plugin_is_installed():
load_plugins()
names = [mod.__name__ for mod in pm.get_plugins()]
assert "llm_cmd" in names

def test_print_only_flag():
load_plugins()

cli = click.Group()
pm.hook.register_commands(cli=cli)
cmd = cli.commands['cmd']
assert any(opt.name == "print_only" for opt in cmd.params)