-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Add support for named templates that can be defined in configuration files and used with interactive prompts for missing template variables.
Context
Currently, jp query supports basic templating with the --template flag, where template variables are resolved from the template.values configuration. However, users must manually configure all template values in advance, and there's no way to define reusable named templates.
This enhancement would allow users to define named templates in their configuration files and use them with a simple command like jp query --template <template_name>. When template variables are not pre-configured, the system would interactively prompt the user to provide values using the existing inquire crate integration.
Alternatives
Users can currently work around this by:
- Pre-defining all template values in
template.valuesconfig - Using the existing
--templateflag with manually crafted queries - Creating shell scripts or aliases to wrap common query patterns
However, these alternatives require more setup and don't provide the interactive experience that would make templates truly user-friendly.
Proposed Implementation
Extend the existing template system to support named templates stored in configuration files. Add a new CLI flag --template-field=key=value to allow setting template variables directly from the command line. When template variables are undefined, use the inquire crate to prompt users interactively.
The implementation would involve:
- Adding a
templatessection to the configuration schema - Modifying the query command to accept template names
- Integrating interactive prompts for undefined variables
- Supporting both CLI-provided and config-provided template values
Tasks
Extend the Template configuration struct to support named templates
- Add
--template-fieldCLI argument parsing to the query command - Integrate
inquireprompts for missing template variables - Update template rendering logic to handle named templates
- Add configuration file examples and documentation
Resources
blob/main/crates/jp_config/src/template.rs
blob/main/crates/jp_cli/src/cmd/query.rs#L28-L66
blob/main/crates/jp_cli/src/cmd/query.rs#L295-L305