Skip to content

Commit 6c2f019

Browse files
committed
Support .wizrc to set default command line args
1 parent 5565dc4 commit 6c2f019

File tree

7 files changed

+559
-8
lines changed

7 files changed

+559
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ dist/
55
*.pyc
66
__pycache__/
77
.DS_Store
8+
.wizrc

.wizrc.example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Example .wizrc configuration
2+
files: &files
3+
exclude: ["*.md", "*.log"]
4+
5+
prompt:
6+
<<: *files

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export ANTHROPIC_API_KEY=your_api_key_here
3030
- 🖼️ Includes image attachment capabilities for visual context
3131
- 🚫 Exclude files via regex patterns to fine-tune your magical selection
3232
- 📋 Preview files that would be included before spending API tokens
33+
- 📝 Supports `.wizrc` configuration file for persistent command-line arguments
3334

3435
## 🧙 Installation
3536

@@ -70,9 +71,38 @@ For permanent enchantment, add this to your shell profile (.bashrc, .zshrc, etc.
7071

7172
> 🔴 **Note**: The `ANTHROPIC_API_KEY` environment variable is **required**. The tool will not function without it properly set. If you encounter errors about unauthorized access or missing API keys, please verify this variable is correctly set.
7273
74+
## 📝 Configuration with .wizrc
75+
76+
You can store command configurations in a `.wizrc` YAML file in your project directory:
77+
78+
```yaml
79+
# Example .wizrc file
80+
files:
81+
exclude: ["*test*"]
82+
image: ["screenshot.png"]
83+
max_tokens: 80000
84+
85+
# Example .wizrc configuration
86+
files: &files
87+
exclude: ["*.log", "build", "dist"]
88+
89+
prompt:
90+
<<: *files
91+
```
92+
93+
The tool will automatically load this configuration and apply it to corresponding commands. The example above shows:
94+
- Setting exclusion patterns to ignore specific files
95+
- Using YAML anchors (`&files`) to define common configurations
96+
- Inheriting settings between commands with YAML merge keys (`<<: *files`)
97+
- Configuring command-specific options like max_tokens
98+
99+
Each top-level key in the YAML corresponds to a subcommand, with nested options matching the command's options. All configuration is completely optional, and command-line arguments will override settings in `.wizrc` when provided.
100+
101+
The `.wizrc` file is automatically excluded from git via `.gitignore`.
102+
73103
## 🪄 Usage
74104

75-
Wizard Prompt CLI offers three main incantations:
105+
Wizard Prompt CLI offers three main incantations and supports configuration via a `.wizrc` file:
76106

77107
### 📝 Prompt Command
78108

@@ -297,4 +327,4 @@ echo $env:ANTHROPIC_API_KEY
297327

298328
<p align="center">
299329
<i>✨ If this magical tool helped you, consider giving it a star! ✨</i>
300-
</p>
330+
</p>

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "wizard-prompt-cli"
3-
version = "0.3.1"
3+
version = "0.4.0"
44
description = "A CLI tool for building and running magical LLM prompts"
55
readme = "README.md"
66
requires-python = ">=3.11"
@@ -10,6 +10,7 @@ authors = [
1010
dependencies = [
1111
"anthropic>=0.49.0",
1212
"click>=8.1.8",
13+
"pyyaml>=6.0.2",
1314
"rich>=13.9.4",
1415
]
1516

tests/test_cli.py

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import pytest
2+
import os
23
from unittest.mock import patch, MagicMock, mock_open
34
from click.testing import CliRunner
4-
from wiz import cli, files, apply
5+
from wiz import cli, files, apply, load_wizrc_config
56

67
def test_files_command(runner):
78
"""Test the 'files' command."""
@@ -70,4 +71,72 @@ def test_prompt_command(runner):
7071
assert result.exit_code == 0
7172
# Verify reply was called with the question
7273
mock_reply.assert_called_once()
73-
assert 'How can I improve this code?' in mock_reply.call_args[0][0]
74+
assert 'How can I improve this code?' in mock_reply.call_args[0][0]
75+
76+
def test_load_wizrc_config():
77+
"""Test loading configuration from .wizrc file."""
78+
wizrc_yaml = """
79+
prompt:
80+
exclude: ["*.log", "*.tmp"]
81+
max_tokens: 80000
82+
file: ["test.py", "main.py"]
83+
files:
84+
exclude: ["*.md"]
85+
"""
86+
expected_config = {
87+
'prompt': {
88+
'exclude': ['*.log', '*.tmp'],
89+
'max_tokens': 80000,
90+
'file': ['test.py', 'main.py']
91+
},
92+
'files': {
93+
'exclude': ['*.md']
94+
}
95+
}
96+
97+
with patch('os.path.exists', return_value=True):
98+
with patch('builtins.open', mock_open(read_data=wizrc_yaml)):
99+
with patch('wiz.console.print'): # Suppress console output during test
100+
config = load_wizrc_config()
101+
assert config == expected_config
102+
103+
def test_load_wizrc_empty_file():
104+
"""Test loading from empty .wizrc file."""
105+
with patch('os.path.exists', return_value=True):
106+
with patch('builtins.open', mock_open(read_data='')):
107+
with patch('wiz.console.print'): # Suppress console output during test
108+
config = load_wizrc_config()
109+
assert config == {}
110+
111+
def test_load_wizrc_file_not_exists():
112+
"""Test when .wizrc file doesn't exist."""
113+
with patch('os.path.exists', return_value=False):
114+
config = load_wizrc_config()
115+
assert config == {}
116+
117+
def test_cli_with_wizrc_config(runner):
118+
"""Test CLI with .wizrc configuration."""
119+
120+
# Test that configuration from .wizrc is applied
121+
with patch('wiz.load_wizrc_config') as mock_load_config:
122+
# Mock the config that would be loaded from .wizrc
123+
mock_load_config.return_value = {
124+
'prompt': {
125+
'exclude': ['*.log'],
126+
'max_tokens': 80000,
127+
'file': ['test.py']
128+
}
129+
}
130+
131+
with patch('wiz.reply') as mock_reply:
132+
mock_reply.return_value = "Response content"
133+
134+
# Mock file operations
135+
with patch('builtins.open', mock_open()):
136+
# Run the command
137+
with patch('wiz.console.print'): # Suppress console output
138+
result = runner.invoke(cli, ['prompt', 'How can I improve this code?'])
139+
140+
assert result.exit_code == 0
141+
# Verify config was loaded
142+
mock_load_config.assert_called_once()

0 commit comments

Comments
 (0)