Skip to content

Commit

Permalink
No longer auto-read from STDIN if there are files given (#1115)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikefarah committed Feb 20, 2022
1 parent 75fffc1 commit 304fc46
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
13 changes: 9 additions & 4 deletions acceptance_tests/basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,35 +62,40 @@ 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"
}

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"
}

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"
}

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"
}

Expand Down
6 changes: 5 additions & 1 deletion cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 304fc46

Please sign in to comment.