Add --raw flag to vals eval for JSONC, JSON5, and plain text support #858
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds support for JSONC (JSON with comments), JSON5, and plain text files to the
vals evalcommand by introducing a--rawflag. This addresses the feature request for a "loose mode" similar toenvsubstthat works with any text format while keeping the powerfulref+syntax.Problem
Currently,
vals evalrequires valid YAML or JSON input. This limitation prevents users from usingvalswith:Users who want to use
valsfor simple string substitution in configuration files had to either usevals get(which only works with single strings) or ensure their files are valid YAML/JSON.Solution
Added a
--rawflag to thevals evalcommand that treats input as raw text instead of parsing it as YAML/JSON. When enabled:vals.Get()function performs string substitution on the entire contentref+expressions are replaced with their actual values-o) is ignored since the format is preserved as-isUsage Examples
Plain text configuration:
JSONC with comments:
$ cat config.jsonc { // Database configuration "database": "ref+vault://secret/data/db#/url", /* API Keys */ "api_key": "ref+awssecrets://prod/api#/key" } $ vals eval -f config.jsonc --raw { // Database configuration "database": "postgres://prod-db:5432/myapp", /* API Keys */ "api_key": "sk-prod-1234567890" }JSON5 with trailing commas:
Implementation Details
New
RawInput()function inio.go- Reads raw text content from files or stdin, similar toInputs()but returns a string instead of YAML nodesUpdated
vals evalcommand incmd/vals/main.go- Added--rawflag handling that bypasses YAML/JSON parsing and usesvals.Get()for text substitutionComprehensive tests - Added unit tests for
RawInput()and integration tests for raw mode with various file formatsDocumentation - Added "Raw Text Mode" section to README with practical examples
Benefits
--rawis not usedvals.Get()logic for substitutionenvsubstbut withvalsprovider powerTesting
RawInput()functionCloses #XXX
Original prompt
Fixes #731
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.