Skip to content

Add named templates with interactive prompts for jp query #178

@JeanMertz

Description

@JeanMertz

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.values config
  • Using the existing --template flag 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:

  1. Adding a templates section to the configuration schema
  2. Modifying the query command to accept template names
  3. Integrating interactive prompts for undefined variables
  4. Supporting both CLI-provided and config-provided template values

Tasks

Extend the Template configuration struct to support named templates

  • Add --template-field CLI argument parsing to the query command
  • Integrate inquire prompts 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions