diff --git a/acceptance_tests/basic.sh b/acceptance_tests/basic.sh index 2d0c0f9b..35e732b4 100755 --- a/acceptance_tests/basic.sh +++ b/acceptance_tests/basic.sh @@ -13,7 +13,56 @@ testBasicEvalRoundTrip() { testBasicPipeWithDot() { ./yq -n ".a = 123" > test.yml X=$(cat test.yml | ./yq '.') - assertEquals 123 "$X" + assertEquals "a: 123" "$X" +} + +testBasicAllFiles() { + ./yq -n ".a = 123" > test.yml + ./yq -n ".a = 124" > test2.yml + X=$(./yq test.yml test2.yml) + Y=$(./yq e '.' test.yml test2.yml) + assertEquals "$Y" "$X" +} + +testBasicEvalAllAllFiles() { + ./yq -n ".a = 123" > test.yml + ./yq -n ".a = 124" > test2.yml + X=$(./yq ea test.yml test2.yml) + Y=$(./yq e '.' test.yml test2.yml) + assertEquals "$Y" "$X" +} + + +testBasicStdInWithFiles() { + ./yq -n ".a = 123" > test.yml + ./yq -n ".a = 124" > test2.yml + X=$(cat test.yml | ./yq - test2.yml) + Y=$(./yq e '.' test.yml test2.yml) + assertEquals "$Y" "$X" +} + +testBasicEvalAllStdInWithFiles() { + ./yq -n ".a = 123" > test.yml + ./yq -n ".a = 124" > test2.yml + X=$(cat test.yml | ./yq ea - test2.yml) + Y=$(./yq e '.' test.yml test2.yml) + assertEquals "$Y" "$X" +} + +testBasicStdInWithFilesReverse() { + ./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) + assertEquals "$Y" "$X" +} + +testBasicEvalAllStdInWithFilesReverse() { + ./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) + assertEquals "$Y" "$X" } testBasicEvalRoundTripNoEval() { diff --git a/cmd/evaluate_all_command.go b/cmd/evaluate_all_command.go index 549f1f74..63a65707 100644 --- a/cmd/evaluate_all_command.go +++ b/cmd/evaluate_all_command.go @@ -144,7 +144,13 @@ func evaluateAll(cmd *cobra.Command, args []string) (cmdError error) { err = allAtOnceEvaluator.EvaluateFiles(processExpression(""), []string{args[0]}, printer, leadingContentPreProcessing, decoder) } default: - err = allAtOnceEvaluator.EvaluateFiles(processExpression(args[0]), args[1:], printer, leadingContentPreProcessing, decoder) + // the first argument is either an expression - or a file. + if args[0] == "-" || maybeFile(args[0]) { + err = allAtOnceEvaluator.EvaluateFiles(processExpression(""), args, printer, leadingContentPreProcessing, decoder) + } else { + // first argument is an expression, the rest are files. + err = allAtOnceEvaluator.EvaluateFiles(processExpression(args[0]), args[1:], printer, leadingContentPreProcessing, decoder) + } } completedSuccessfully = err == nil diff --git a/cmd/evalute_sequence_command.go b/cmd/evalute_sequence_command.go index bfa7a7c7..af964a13 100644 --- a/cmd/evalute_sequence_command.go +++ b/cmd/evalute_sequence_command.go @@ -162,7 +162,15 @@ func evaluateSequence(cmd *cobra.Command, args []string) (cmdError error) { err = streamEvaluator.EvaluateFiles(processExpression(""), []string{args[0]}, printer, leadingContentPreProcessing, decoder) } default: - err = streamEvaluator.EvaluateFiles(processExpression(args[0]), args[1:], printer, leadingContentPreProcessing, decoder) + // the first argument is either an expression - or a file. + if args[0] == "-" || maybeFile(args[0]) { + // its a file, there is no expression given + err = streamEvaluator.EvaluateFiles(processExpression(""), args, printer, leadingContentPreProcessing, decoder) + } else { + // first argument is an expression, the rest are files. + err = streamEvaluator.EvaluateFiles(processExpression(args[0]), args[1:], printer, leadingContentPreProcessing, decoder) + } + } completedSuccessfully = err == nil