Skip to content

Add basic interactive prompt mode to fill variables#2

Merged
eyalzh merged 1 commit intomainfrom
add-interactive
Aug 7, 2025
Merged

Add basic interactive prompt mode to fill variables#2
eyalzh merged 1 commit intomainfrom
add-interactive

Conversation

@eyalzh
Copy link
Owner

@eyalzh eyalzh commented Aug 7, 2025

No description provided.

@eyalzh eyalzh requested a review from Copilot August 7, 2025 15:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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('[')):
Copy link

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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('[')):

Copilot uses AI. Check for mistakes.
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()
Copy link

Copilot AI Aug 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
@eyalzh eyalzh merged commit daed9f8 into main Aug 7, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant