Add yqFlags to expressionScenario for doc command snippets; fix system op docs

Agent-Logs-Url: https://github.com/mikefarah/yq/sessions/3f8a5375-25fd-4428-a8e6-b630194c36b2

Co-authored-by: mikefarah <1151925+mikefarah@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-03-28 02:08:14 +00:00 committed by GitHub
parent da611f7a2b
commit 884c2d8b6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 5 deletions

View File

@ -47,7 +47,7 @@ country: Australia
``` ```
then then
```bash ```bash
yq '.country = system("/usr/bin/echo"; "test")' sample.yml yq --enable-system-operator '.country = system("/usr/bin/echo"; "test")' sample.yml
``` ```
will output will output
```yaml ```yaml
@ -63,7 +63,7 @@ a: hello
``` ```
then then
```bash ```bash
yq '.a = system("/usr/bin/echo")' sample.yml yq --enable-system-operator '.a = system("/usr/bin/echo")' sample.yml
``` ```
will output will output
```yaml ```yaml

View File

@ -55,6 +55,7 @@ func TestSystemOperatorEnabledScenarios(t *testing.T) {
{ {
description: "Run a command with an argument", description: "Run a command with an argument",
subdescription: "Use `--enable-system-operator` to enable the system operator.", subdescription: "Use `--enable-system-operator` to enable the system operator.",
yqFlags: "--enable-system-operator",
document: "country: Australia", document: "country: Australia",
expression: `.country = system("` + echoPath + `"; "test")`, expression: `.country = system("` + echoPath + `"; "test")`,
expected: []string{ expected: []string{
@ -64,6 +65,7 @@ func TestSystemOperatorEnabledScenarios(t *testing.T) {
{ {
description: "Run a command without arguments", description: "Run a command without arguments",
subdescription: "Omit the semicolon and args to run the command with no extra arguments.", subdescription: "Omit the semicolon and args to run the command with no extra arguments.",
yqFlags: "--enable-system-operator",
document: "a: hello", document: "a: hello",
expression: `.a = system("` + echoPath + `")`, expression: `.a = system("` + echoPath + `")`,
expected: []string{ expected: []string{

View File

@ -31,6 +31,7 @@ type expressionScenario struct {
dontFormatInputForDoc bool // dont format input doc for documentation generation dontFormatInputForDoc bool // dont format input doc for documentation generation
requiresFormat string requiresFormat string
skipForGoccy bool skipForGoccy bool
yqFlags string // extra yq flags to include in generated doc command snippets
} }
var goccyTesting = false var goccyTesting = false
@ -356,14 +357,22 @@ func documentInput(w *bufio.Writer, s expressionScenario) (string, string) {
writeOrPanic(w, "then\n") writeOrPanic(w, "then\n")
flagsPrefix := ""
if s.yqFlags != "" {
flagsPrefix = s.yqFlags + " "
}
if s.expression != "" { if s.expression != "" {
writeOrPanic(w, fmt.Sprintf("```bash\n%vyq %v'%v' %v\n```\n", envCommand, command, strings.ReplaceAll(s.expression, "'", `'\''`), files)) writeOrPanic(w, fmt.Sprintf("```bash\n%vyq %v%v'%v' %v\n```\n", envCommand, flagsPrefix, command, strings.ReplaceAll(s.expression, "'", `'\''`), files))
} else { } else {
writeOrPanic(w, fmt.Sprintf("```bash\n%vyq %v%v\n```\n", envCommand, command, files)) writeOrPanic(w, fmt.Sprintf("```bash\n%vyq %v%v%v\n```\n", envCommand, flagsPrefix, command, files))
} }
} else { } else {
writeOrPanic(w, "Running\n") writeOrPanic(w, "Running\n")
writeOrPanic(w, fmt.Sprintf("```bash\n%vyq %v--null-input '%v'\n```\n", envCommand, command, s.expression)) flagsPrefix := ""
if s.yqFlags != "" {
flagsPrefix = s.yqFlags + " "
}
writeOrPanic(w, fmt.Sprintf("```bash\n%vyq %v%v--null-input '%v'\n```\n", envCommand, flagsPrefix, command, s.expression))
} }
return formattedDoc, formattedDoc2 return formattedDoc, formattedDoc2
} }