mirror of
https://github.com/mikefarah/yq.git
synced 2024-11-14 07:08:06 +00:00
No longer have to specify eval!
This commit is contained in:
parent
fc276ff450
commit
4ec533bc1b
@ -10,6 +10,12 @@ testBasicEvalRoundTrip() {
|
|||||||
assertEquals 123 "$X"
|
assertEquals 123 "$X"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testBasicEvalRoundTripNoEval() {
|
||||||
|
./yq -n ".a = 123" > test.yml
|
||||||
|
X=$(./yq '.a' test.yml)
|
||||||
|
assertEquals 123 "$X"
|
||||||
|
}
|
||||||
|
|
||||||
testBasicStdInWithOneArg() {
|
testBasicStdInWithOneArg() {
|
||||||
./yq e -n ".a = 123" > test.yml
|
./yq e -n ".a = 123" > test.yml
|
||||||
X=$(cat test.yml | ./yq e ".a")
|
X=$(cat test.yml | ./yq e ".a")
|
||||||
@ -17,6 +23,9 @@ testBasicStdInWithOneArg() {
|
|||||||
|
|
||||||
X=$(cat test.yml | ./yq ea ".a")
|
X=$(cat test.yml | ./yq ea ".a")
|
||||||
assertEquals 123 "$X"
|
assertEquals 123 "$X"
|
||||||
|
|
||||||
|
X=$(cat test.yml | ./yq ".a")
|
||||||
|
assertEquals 123 "$X"
|
||||||
}
|
}
|
||||||
|
|
||||||
testBasicUpdateInPlaceSequence() {
|
testBasicUpdateInPlaceSequence() {
|
||||||
@ -28,6 +37,15 @@ EOL
|
|||||||
assertEquals "10" "$X"
|
assertEquals "10" "$X"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testBasicUpdateInPlaceSequenceNoEval() {
|
||||||
|
cat >test.yml <<EOL
|
||||||
|
a: 0
|
||||||
|
EOL
|
||||||
|
./yq -i ".a = 10" test.yml
|
||||||
|
X=$(./yq '.a' test.yml)
|
||||||
|
assertEquals "10" "$X"
|
||||||
|
}
|
||||||
|
|
||||||
testBasicUpdateInPlaceSequenceEvalAll() {
|
testBasicUpdateInPlaceSequenceEvalAll() {
|
||||||
cat >test.yml <<EOL
|
cat >test.yml <<EOL
|
||||||
a: 0
|
a: 0
|
||||||
@ -49,6 +67,12 @@ testBasicExitStatus() {
|
|||||||
assertEquals 1 "$?"
|
assertEquals 1 "$?"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testBasicExitStatusNoEval() {
|
||||||
|
echo "a: cat" > test.yml
|
||||||
|
X=$(./yq -e '.z' test.yml 2&>/dev/null)
|
||||||
|
assertEquals 1 "$?"
|
||||||
|
}
|
||||||
|
|
||||||
testBasicExtractFieldWithSeperator() {
|
testBasicExtractFieldWithSeperator() {
|
||||||
cat >test.yml <<EOL
|
cat >test.yml <<EOL
|
||||||
---
|
---
|
||||||
|
@ -13,7 +13,7 @@ func createEvaluateSequenceCommand() *cobra.Command {
|
|||||||
var cmdEvalSequence = &cobra.Command{
|
var cmdEvalSequence = &cobra.Command{
|
||||||
Use: "eval [expression] [yaml_file1]...",
|
Use: "eval [expression] [yaml_file1]...",
|
||||||
Aliases: []string{"e"},
|
Aliases: []string{"e"},
|
||||||
Short: "Apply the expression to each document in each yaml file in sequence",
|
Short: "(default) Apply the expression to each document in each yaml file in sequence",
|
||||||
Example: `
|
Example: `
|
||||||
# Reads field under the given path for each file
|
# Reads field under the given path for each file
|
||||||
yq e '.a.b' f1.yml f2.yml
|
yq e '.a.b' f1.yml f2.yml
|
||||||
|
@ -14,6 +14,12 @@ 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.`,
|
||||||
|
Example: `
|
||||||
|
# yq defaults to 'eval' command if no command is specified. See "yq eval --help" for more examples.
|
||||||
|
cat myfile.yml | yq '.stuff' # outputs the data at the "stuff" node from "myfile.yml"
|
||||||
|
|
||||||
|
yq -i '.stuff = "foo"' myfile.yml # update myfile.yml inplace
|
||||||
|
`,
|
||||||
|
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if version {
|
if version {
|
||||||
|
11
yq.go
11
yq.go
@ -8,6 +8,17 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cmd := command.New()
|
cmd := command.New()
|
||||||
|
|
||||||
|
args := os.Args[1:]
|
||||||
|
|
||||||
|
_, _, err := cmd.Find(args)
|
||||||
|
if err != nil {
|
||||||
|
// default command when nothing matches...
|
||||||
|
newArgs := []string{"eval"}
|
||||||
|
cmd.SetArgs(append(newArgs, os.Args[1:]...))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if err := cmd.Execute(); err != nil {
|
if err := cmd.Execute(); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user