validate flags before reading stdin and reject bare -C with -j/-1/-2
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user