No longer auto-read from STDIN if there are files given (#1115)

This commit is contained in:
Mike Farah 2022-02-20 13:15:21 +11:00
parent 75fffc17e1
commit 304fc462a4
2 changed files with 14 additions and 5 deletions

View File

@ -62,11 +62,16 @@ testBasicEvalAllAllFiles() {
assertEquals "$Y" "$X"
}
# when given a file, don't read STDIN
# otherwise strange things start happening
# in scripts
# https://github.com/mikefarah/yq/issues/1115
testBasicCatWithFilesNoDash() {
./yq -n ".a = 123" > test.yml
./yq -n ".a = 124" > test2.yml
X=$(cat test.yml | ./yq test2.yml)
Y=$(./yq e '.' test2.yml test.yml)
Y=$(./yq e '.' test2.yml)
assertEquals "$Y" "$X"
}
@ -74,7 +79,7 @@ testBasicEvalAllCatWithFilesNoDash() {
./yq -n ".a = 123" > test.yml
./yq -n ".a = 124" > test2.yml
X=$(cat test.yml | ./yq ea test2.yml)
Y=$(./yq e '.' test2.yml test.yml)
Y=$(./yq e '.' test2.yml)
assertEquals "$Y" "$X"
}
@ -82,7 +87,7 @@ testBasicCatWithFilesNoDashWithExp() {
./yq -n ".a = 123" > test.yml
./yq -n ".a = 124" > test2.yml
X=$(cat test.yml | ./yq '.a' test2.yml)
Y=$(./yq e '.a' test2.yml test.yml)
Y=$(./yq e '.a' test2.yml)
assertEquals "$Y" "$X"
}
@ -90,7 +95,7 @@ testBasicEvalAllCatWithFilesNoDashWithExp() {
./yq -n ".a = 123" > test.yml
./yq -n ".a = 124" > test2.yml
X=$(cat test.yml | ./yq ea '.a' test2.yml)
Y=$(./yq e '.a' test2.yml test.yml)
Y=$(./yq e '.a' test2.yml)
assertEquals "$Y" "$X"
}

View File

@ -117,7 +117,11 @@ func maybeFile(str string) bool {
}
func processStdInArgs(pipingStdin bool, args []string) []string {
if !pipingStdin {
// if we've been given a file, don't automatically
// read from stdin.
// this happens if there is more than one argument
// or only one argument and its a file
if !pipingStdin || len(args) > 1 || (len(args) > 0 && maybeFile(args[0])) {
return args
}