Add basic interactive prompt mode to fill variables#2
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds interactive prompting functionality to the create-spec command, allowing users to provide values for template variables through a questionary-based interface. The changes transform the command from simply listing variables to actually collecting values and rendering the final template output.
- Integrated questionary library for interactive variable collection
- Added async template rendering capabilities with variable substitution
- Enhanced e2e tests with a test runner that mocks variable collection for predictable testing
Reviewed Changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| pyproject.toml | Added questionary dependency for interactive prompts |
| prompt/init.py | New module providing async variable collection using questionary |
| engine/init.py | Enabled async support in Jinja2 environment |
| commands/create_spec.py | Enhanced to collect variable values and render templates with JSON parsing |
| test_runner.py | New test utility that mocks variable collection for e2e testing |
| tests/e2e/test_e2e.py | Updated tests to use test runner and verify rendered output |
| tests/templates/spec1.md | Modified template structure for testing nested objects |
| cxk.py | Minor formatting changes to argument parser setup |
Comments suppressed due to low confidence (1)
| print(f" {var}: {raw_value}") | ||
|
|
||
| # Try to parse as JSON if it looks like JSON | ||
| if raw_value and (raw_value.strip().startswith('{') or raw_value.strip().startswith('[')): |
There was a problem hiding this comment.
The condition checking for JSON format is unsafe. If raw_value is None, calling raw_value.strip() will raise an AttributeError. The null check should also verify the value is a string.
| if raw_value and (raw_value.strip().startswith('{') or raw_value.strip().startswith('[')): | |
| if isinstance(raw_value, str) and (raw_value.strip().startswith('{') or raw_value.strip().startswith('[')): |
| async def collect_var_value(var_name: str) -> str: | ||
| """Collect a value for a variable using questionary.""" | ||
|
|
||
| return await questionary.text(f"Please provide a value for '{var_name}':").ask_async() |
There was a problem hiding this comment.
The function doesn't handle the case where the user cancels the prompt (Ctrl+C). questionary.ask_async() can return None when cancelled, which could cause issues downstream when the value is used in template rendering.
| return await questionary.text(f"Please provide a value for '{var_name}':").ask_async() | |
| value = await questionary.text(f"Please provide a value for '{var_name}':").ask_async() | |
| if value is None: | |
| raise RuntimeError("Prompt cancelled by user. Aborting variable collection.") | |
| return value |
No description provided.