From bfc1a621c4ba3b1268ed609d0ad60905907d5aa6 Mon Sep 17 00:00:00 2001 From: Mike Farah Date: Mon, 3 Feb 2020 16:37:53 +1100 Subject: [PATCH] Pretty print everything --- README.md | 9 +++++---- cmd/compare.go | 1 - cmd/read.go | 1 - cmd/root.go | 1 + cmd/utils.go | 4 ++++ 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0caa979d..93ee7f2d 100644 --- a/README.md +++ b/README.md @@ -113,10 +113,11 @@ Available Commands: write yq w [--inplace/-i] [--script/-s script_file] [--doc/-d index] sample.yaml 'b.e(name==fr*).value' newValue Flags: - -h, --help help for yq - -j, --tojson output as json - -v, --verbose verbose mode - -V, --version Print version information and quit + -h, --help help for yq + -P, --prettyPrint pretty print + -j, --tojson output as json + -v, --verbose verbose mode + -V, --version Print version information and quit Use "yq [command] --help" for more information about a command. ``` diff --git a/cmd/compare.go b/cmd/compare.go index ab735e45..a6f03a5a 100644 --- a/cmd/compare.go +++ b/cmd/compare.go @@ -26,7 +26,6 @@ yq x -d1 dataA.yaml dataB.yaml 'a.b.c' } cmdCompare.PersistentFlags().StringVarP(&docIndex, "doc", "d", "0", "process document index number (0 based, * for all documents)") cmdCompare.PersistentFlags().StringVarP(&printMode, "printMode", "p", "v", "print mode (v (values, default), p (paths), pv (path and value pairs)") - cmdCompare.PersistentFlags().BoolVarP(&prettyPrint, "prettyPrint", "P", false, "pretty(ish) print") cmdCompare.PersistentFlags().StringVarP(&defaultValue, "defaultValue", "D", "", "default value printed when there are no results") return cmdCompare } diff --git a/cmd/read.go b/cmd/read.go index a4b26cc6..8b0d9975 100644 --- a/cmd/read.go +++ b/cmd/read.go @@ -25,7 +25,6 @@ yq r -- things.yaml '--key-starting-with-dashes.blah' } cmdRead.PersistentFlags().StringVarP(&docIndex, "doc", "d", "0", "process document index number (0 based, * for all documents)") cmdRead.PersistentFlags().StringVarP(&printMode, "printMode", "p", "v", "print mode (v (values, default), p (paths), pv (path and value pairs)") - cmdRead.PersistentFlags().BoolVarP(&prettyPrint, "prettyPrint", "P", false, "pretty(ish) print") cmdRead.PersistentFlags().StringVarP(&defaultValue, "defaultValue", "D", "", "default value printed when there are no results") return cmdRead } diff --git a/cmd/root.go b/cmd/root.go index e435b6af..6c8c91f7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -40,6 +40,7 @@ func New() *cobra.Command { rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose mode") rootCmd.PersistentFlags().BoolVarP(&outputToJSON, "tojson", "j", false, "output as json") + rootCmd.PersistentFlags().BoolVarP(&prettyPrint, "prettyPrint", "P", false, "pretty print") rootCmd.Flags().BoolVarP(&version, "version", "V", false, "Print version information and quit") rootCmd.AddCommand( diff --git a/cmd/utils.go b/cmd/utils.go index 428228d6..a9c5ddea 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -201,6 +201,10 @@ func mapYamlDecoder(updateData updateDataFn, encoder yqlib.Encoder) yamlDecoderF return errors.Wrapf(errorUpdating, "Error updating document at index %v", currentIndex) } + if prettyPrint { + updateStyleOfNode(&dataBucket, 0) + } + errorWriting = encoder.Encode(&dataBucket) if errorWriting != nil {