validate flags before reading stdin and reject bare -C with -j/-1/-2
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful

This commit is contained in:
2026-10-13 20:41:31 +11:00
parent 8b9ac394a0
commit fae7dad630
2 changed files with 94 additions and 10 deletions
+16 -10
View File
@@ -357,22 +357,28 @@ func run(cfg config, nodeName, factName, match string, showRole, partial, invers
return nil
}
hasQuery := showRole || factName != ""
// Bare -C counts already-looked-up piped lines; only it needs stdin to validate.
bareCount := count && !hasQuery && !nodeOnly && !valueOnly && !ansible && !jsonMode && nodeName == ""
countErr := fmt.Errorf("-R or -F must be used with -1, -2, -C, or -A")
if (nodeOnly || valueOnly || (count && !bareCount) || ansible) && !hasQuery {
return countErr
}
if (match != "" || partial || inverse) && !hasQuery {
return fmt.Errorf("-R or -F must be used with -m, -p, or -i")
}
var reader *bufio.Reader
piped := false
if nodeName == "" {
reader, piped = stdinReader(os.Stdin)
}
// Bare -C on piped input counts the already-looked-up lines instead of querying.
passthrough := count && piped && !showRole && factName == ""
if (nodeOnly || valueOnly || (count && !passthrough) || ansible) && !showRole && factName == "" {
return fmt.Errorf("-R or -F must be used with -1, -2, -C, or -A")
}
if (match != "" || partial || inverse) && !showRole && factName == "" {
return fmt.Errorf("-R or -F must be used with -m, -p, or -i")
}
if passthrough {
if bareCount {
if !piped {
return countErr
}
var lines []string
scanner := bufio.NewScanner(reader)
for scanner.Scan() {