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
6 changes: 6 additions & 0 deletions hey/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ def main(

if ctx.invoked_subcommand is None:
user_input = open_tmp_editor()
if not user_input.strip():
console.print("No input provided.")
raise typer.Exit(code=1)
markdown_input = Markdown(
user_input, code_theme=configs.get("code_block_theme")
)
Expand Down Expand Up @@ -74,6 +77,9 @@ def ask(
Ask Hey directly in-command.
"""

if not user_input.strip():
console.print("No input provided.")
raise typer.Exit(code=1)
result = answer(user_input, no_style)
console.print(result)

Expand Down
2 changes: 1 addition & 1 deletion hey/configs/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
def create():
"""Create a base config file."""
if not config_exists():
os.makedirs(APP_CONFIG_DIR)
os.makedirs(APP_CONFIG_DIR, exist_ok=True)
init_config()
else:
if Confirm.ask(
Expand Down
3 changes: 2 additions & 1 deletion hey/configs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def read_configs() -> dict:


def init_config():
with open(CONFIG_FILE_PATH, "w+") as conf_file:
os.makedirs(APP_CONFIG_DIR, exist_ok=True)
with open(CONFIG_FILE_PATH, "w+", encoding="utf-8") as conf_file:
conf_file.write(json.dumps(BASE_CONFIG, indent=4))


Expand Down
2 changes: 1 addition & 1 deletion hey/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __init__(
self.prompt = prompt

def ask(self, text: str) -> str:
if not text:
if not text or not text.strip():
raise ValueError("provide a valid input.")
try:
client_mindsdb_serve = OpenAI(
Expand Down
19 changes: 19 additions & 0 deletions tests/test_configs_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import json
from pathlib import Path

from hey.configs import utils
from hey.consts import BASE_CONFIG


def test_init_config_creates_directory_and_file(tmp_path, monkeypatch):
config_dir = tmp_path / "hey"
config_file = config_dir / "config.json"

monkeypatch.setattr(utils, "APP_CONFIG_DIR", config_dir)
monkeypatch.setattr(utils, "CONFIG_FILE_PATH", config_file)

utils.init_config()

assert config_file.exists()
loaded = json.loads(config_file.read_text(encoding="utf-8"))
assert loaded == BASE_CONFIG