Skip to content

Commit

Permalink
Append stdin to the user query (#31)
Browse files Browse the repository at this point in the history
The stdin was not being appended to the query, which is a bug. This patch should fix it.
  • Loading branch information
r0x0d authored Nov 8, 2024
1 parent bb1a80a commit 00aae37
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
6 changes: 2 additions & 4 deletions command_line_assistant/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
import logging

from command_line_assistant.config import CONFIG_DEFAULT_PATH
from command_line_assistant.utils import read_stdin
Expand Down Expand Up @@ -37,9 +36,8 @@ def get_args():
args.record,
]
input_data = read_stdin()
if not args.query_string and input_data:
logging.debug("stdin detected")
args.query_string = input_data.strip()
if input_data and args.query_string:
args.query_string = f"{args.query_string} {input_data.strip()}"

if not any(optional_args) and not args.query_string:
parser.error("Query string is required if no optional arguments are provided.")
Expand Down
3 changes: 1 addition & 2 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import sys
from unittest import mock

import pytest

Expand All @@ -16,7 +15,7 @@ def mock_cli_arguments(args):

def test_get_args(monkeypatch):
monkeypatch.setattr(sys, "argv", mock_cli_arguments(["test"]))
monkeypatch.setattr(cli, "read_stdin", mock.Mock())
monkeypatch.setattr(cli, "read_stdin", lambda: None)
parser, args = cli.get_args()

assert parser
Expand Down

0 comments on commit 00aae37

Please sign in to comment.