Pretty print everything

This commit is contained in:
Mike Farah 2020-02-03 16:37:53 +11:00
parent 166f866f28
commit bfc1a621c4
5 changed files with 10 additions and 6 deletions

View File

@ -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.
```

View File

@ -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
}

View File

@ -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
}

View File

@ -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(

View File

@ -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 {