diff --git a/CHANGELOG.md b/CHANGELOG.md index be389b6..6c1db58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## TBD ### Features - +* Support `--help` in the `\llm`and `\llm+` command. ([#214](https://github.com/dbcli/litecli/pull/214)) * Make the history file location configurable. ([#206](https://github.com/dbcli/litecli/issues/206)) ### Internal diff --git a/litecli/packages/special/llm.py b/litecli/packages/special/llm.py index b7304a4..4473af3 100644 --- a/litecli/packages/special/llm.py +++ b/litecli/packages/special/llm.py @@ -236,6 +236,10 @@ def handle_llm(text, cur) -> Tuple[str, Optional[str]]: elif parts[0] in LLM_CLI_COMMANDS: capture_output = False use_context = False + # If the user wants to use --help option to see each command and it's description + elif "--help" == parts[0]: + capture_output = False + use_context = False # If the parts doesn't have any known LLM_CLI_COMMANDS then the user is # invoking a question. eg: \llm -m ollama "Most visited urls?" elif not set(parts).intersection(LLM_CLI_COMMANDS): diff --git a/tests/test_llm_special.py b/tests/test_llm_special.py index 2f3b010..25bcc9a 100644 --- a/tests/test_llm_special.py +++ b/tests/test_llm_special.py @@ -87,6 +87,23 @@ def test_llm_command_known_subcommand(mock_run_cmd, mock_llm, executor): # And the function should raise FinishIteration(None) assert exc_info.value.args[0] is None +@patch("litecli.packages.special.llm.llm") +@patch("litecli.packages.special.llm.run_external_cmd") +def test_llm_command_with_help_flag(mock_run_cmd, mock_llm, executor): + """ + If the parts[0] is --help, we do NOT capture output, we just call run_external_cmd + and then raise FinishIteration. + """ + # Let's assume 'models' is in LLM_CLI_COMMANDS + test_text = r"\llm --help" + + with pytest.raises(FinishIteration) as exc_info: + handle_llm(test_text, executor) + + # We check that run_external_cmd was called with these arguments: + mock_run_cmd.assert_called_once_with("llm", "--help", restart_cli=False) + # And the function should raise FinishIteration(None) + assert exc_info.value.args[0] is None @patch("litecli.packages.special.llm.llm") @patch("litecli.packages.special.llm.run_external_cmd")