mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-26 00:15:36 +00:00
Smarter behaviour when piping data in with one argument
This commit is contained in:
parent
c3d815998a
commit
fc276ff450
@ -10,6 +10,15 @@ testBasicEvalRoundTrip() {
|
|||||||
assertEquals 123 "$X"
|
assertEquals 123 "$X"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testBasicStdInWithOneArg() {
|
||||||
|
./yq e -n ".a = 123" > test.yml
|
||||||
|
X=$(cat test.yml | ./yq e ".a")
|
||||||
|
assertEquals 123 "$X"
|
||||||
|
|
||||||
|
X=$(cat test.yml | ./yq ea ".a")
|
||||||
|
assertEquals 123 "$X"
|
||||||
|
}
|
||||||
|
|
||||||
testBasicUpdateInPlaceSequence() {
|
testBasicUpdateInPlaceSequence() {
|
||||||
cat >test.yml <<EOL
|
cat >test.yml <<EOL
|
||||||
a: 0
|
a: 0
|
||||||
|
@ -120,6 +120,10 @@ func evaluateAll(cmd *cobra.Command, args []string) (cmdError error) {
|
|||||||
case 1:
|
case 1:
|
||||||
if nullInput {
|
if nullInput {
|
||||||
err = yqlib.NewStreamEvaluator().EvaluateNew(processExpression(args[0]), printer, "")
|
err = yqlib.NewStreamEvaluator().EvaluateNew(processExpression(args[0]), printer, "")
|
||||||
|
} else if pipingStdIn && args[0] != "-" {
|
||||||
|
// must have given a single expression and piping input from stdin
|
||||||
|
err = allAtOnceEvaluator.EvaluateFiles(processExpression(args[0]), []string{"-"}, printer, leadingContentPreProcessing, decoder)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
err = allAtOnceEvaluator.EvaluateFiles(processExpression(""), []string{args[0]}, printer, leadingContentPreProcessing, decoder)
|
err = allAtOnceEvaluator.EvaluateFiles(processExpression(""), []string{args[0]}, printer, leadingContentPreProcessing, decoder)
|
||||||
}
|
}
|
||||||
|
@ -134,6 +134,9 @@ func evaluateSequence(cmd *cobra.Command, args []string) (cmdError error) {
|
|||||||
case 1:
|
case 1:
|
||||||
if nullInput {
|
if nullInput {
|
||||||
err = streamEvaluator.EvaluateNew(processExpression(args[0]), printer, "")
|
err = streamEvaluator.EvaluateNew(processExpression(args[0]), printer, "")
|
||||||
|
} else if pipingStdIn && args[0] != "-" {
|
||||||
|
// must have given a single expression and piping input from stdin
|
||||||
|
err = streamEvaluator.EvaluateFiles(processExpression(args[0]), []string{"-"}, printer, leadingContentPreProcessing, decoder)
|
||||||
} else {
|
} else {
|
||||||
err = streamEvaluator.EvaluateFiles(processExpression(""), []string{args[0]}, printer, leadingContentPreProcessing, decoder)
|
err = streamEvaluator.EvaluateFiles(processExpression(""), []string{args[0]}, printer, leadingContentPreProcessing, decoder)
|
||||||
}
|
}
|
||||||
|
@ -14,13 +14,13 @@ func New() *cobra.Command {
|
|||||||
Short: "yq is a lightweight and portable command-line YAML processor.",
|
Short: "yq is a lightweight and portable command-line YAML processor.",
|
||||||
Long: `yq is a portable command-line YAML processor (https://github.com/mikefarah/yq/)
|
Long: `yq is a portable command-line YAML processor (https://github.com/mikefarah/yq/)
|
||||||
See https://mikefarah.gitbook.io/yq/ for detailed documentation and examples.`,
|
See https://mikefarah.gitbook.io/yq/ for detailed documentation and examples.`,
|
||||||
|
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if version {
|
if version {
|
||||||
cmd.Print(GetVersionDisplay())
|
cmd.Print(GetVersionDisplay())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
cmd.Println(cmd.UsageString())
|
return evaluateSequence(cmd, args)
|
||||||
return nil
|
|
||||||
|
|
||||||
},
|
},
|
||||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user