Enhance parameter handling#46
Merged
Merged
Conversation
…nd improve JSON parsing
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates CLI runtime parameter handling to prefer name=value, parse JSON values when possible, and document the new behavior while retaining legacy name:value support.
Changes:
- Adds
parseParamto validate names, support=/:separators, and fall back to raw strings when JSON parsing fails. - Expands parameter parsing tests for JSON and raw string values.
- Updates README and flag help text for the new parameter syntax.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
README.md |
Documents new --param name=value usage and JSON parsing behavior. |
cmd/params.go |
Implements updated parameter parsing and validation. |
cmd/params_test.go |
Refactors and expands parsing tests. |
cmd/flags.go |
Updates CLI help text for --param. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+27
to
+35
| name, raw, ok := strings.Cut(input, "=") | ||
| if !ok { | ||
| name, raw, ok = strings.Cut(input, ":") | ||
| } | ||
|
|
||
| if !ok { | ||
| return "", nil, fmt.Errorf("invalid param %q: expected name=value", input) | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This pull request updates how runtime parameters are passed and parsed in the CLI, improving flexibility and compatibility with JSON values. The changes affect the CLI flag documentation, parameter parsing logic, and related tests, making parameter input more robust and user-friendly.
Parameter Parsing and CLI Improvements:
key:valuetoname=value, with support for both=and:as separators for backward compatibility. Parameter values are now parsed as JSON when possible; otherwise, they are treated as strings. [1] [2]README.mdand the flag descriptions. [1] [2] [3]Testing Enhancements:
Code Cleanup:
cmd/params.gofor better code hygiene.