diff --git a/cmd/evaluate_all_command.go b/cmd/evaluate_all_command.go index 2470b4a4..68edf62d 100644 --- a/cmd/evaluate_all_command.go +++ b/cmd/evaluate_all_command.go @@ -15,13 +15,27 @@ func createEvaluateAllCommand() *cobra.Command { Aliases: []string{"ea"}, Short: "Loads _all_ yaml documents of _all_ yaml files and runs expression once", Example: ` -# merges f2.yml into f1.yml (inplace) -yq eval-all --inplace 'select(fileIndex == 0) * select(fileIndex == 1)' f1.yml f2.yml +# Merge f2.yml into f1.yml (inplace) +yq eval-all --inplace 'select(fileIndex == 0) * select(fileIndex == 1)' f1.yml f2.yml +## the same command and expression using shortened names: +yq ea -i 'select(fi == 0) * select(fi == 1)' f1.yml f2.yml -# use '-' as a filename to read from STDIN + +# Merge all given files +yq ea '. as $item ireduce ({}; . * $item )' file1.yml file2.yml ... + +# Read from STDIN +## use '-' as a filename to read from STDIN cat file2.yml | yq ea '.a.b' file1.yml - file3.yml `, - Long: "Evaluate All:\nUseful when you need to run an expression across several yaml documents or files. Consumes more memory than eval", + 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. + +## Evaluate All ## +This command loads _all_ yaml documents of _all_ yaml files and runs expression once +Useful when you need to run an expression across several yaml documents or files (like merge). +Note that it consumes more memory than eval. +`, RunE: evaluateAll, } return cmdEvalAll diff --git a/cmd/evalute_sequence_command.go b/cmd/evalute_sequence_command.go index 22aafe65..376cca6e 100644 --- a/cmd/evalute_sequence_command.go +++ b/cmd/evalute_sequence_command.go @@ -13,25 +13,31 @@ func createEvaluateSequenceCommand() *cobra.Command { var cmdEvalSequence = &cobra.Command{ Use: "eval [expression] [yaml_file1]...", Aliases: []string{"e"}, - Short: "Apply expression to each document in each yaml file given in sequence", + Short: "Apply the expression to each document in each yaml file in sequence", Example: ` -# runs the expression against each file, in series -yq e '.a.b | length' f1.yml f2.yml +# Reads field under the given path for each file +yq e '.a.b' f1.yml f2.yml -# prints out the file +# Prints out the file yq e sample.yaml -# use '-' as a filename to read from STDIN +# Read from STDIN +## use '-' as a filename to read from STDIN cat file2.yml | yq e '.a.b' file1.yml - file3.yml -# prints a new yaml document +# Creates a new yaml document +## Note that editing an empty file does not work. yq e -n '.a.b.c = "cat"' - -# updates file.yaml directly +# Update a file inplace yq e '.a.b = "cool"' -i file.yaml `, - Long: "Evaluate Sequence:\nIterate over each yaml document, apply the expression and print the results, in sequence.", + 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. + +## Evaluate Sequence ## +This command iterates over each yaml document from each given file, applies the +expression and prints the result in sequence.`, RunE: evaluateSequence, } return cmdEvalSequence diff --git a/cmd/root.go b/cmd/root.go index da53ede8..3132d0e0 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -11,7 +11,8 @@ func New() *cobra.Command { var rootCmd = &cobra.Command{ Use: "yq", Short: "yq is a lightweight and portable command-line YAML processor.", - Long: `yq is a lightweight and portable command-line YAML processor. It aims to be the jq or sed of yaml files.`, + 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.`, RunE: func(cmd *cobra.Command, args []string) error { if version { cmd.Print(GetVersionDisplay()) diff --git a/cmd/version.go b/cmd/version.go index 79065d1f..3e90afa6 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -25,7 +25,7 @@ const ProductName = "yq" // GetVersionDisplay composes the parts of the version in a way that's suitable // for displaying to humans. func GetVersionDisplay() string { - return fmt.Sprintf("%s version %s\n", ProductName, getHumanVersion()) + return fmt.Sprintf("yq (https://github.com/mikefarah/yq/) version %s\n", getHumanVersion()) } func getHumanVersion() string { diff --git a/cmd/version_test.go b/cmd/version_test.go index b012e652..1ffc64ae 100644 --- a/cmd/version_test.go +++ b/cmd/version_test.go @@ -3,7 +3,7 @@ package cmd import "testing" func TestGetVersionDisplay(t *testing.T) { - var expectedVersion = ProductName + " version " + Version + var expectedVersion = ProductName + " (https://github.com/mikefarah/yq/) version " + Version if VersionPrerelease != "" { expectedVersion = expectedVersion + "-" + VersionPrerelease }