mirror of
https://github.com/mikefarah/yq.git
synced 2024-12-19 20:19:04 +00:00
Refactored code
This commit is contained in:
parent
001925a4d4
commit
6b566fd983
26
yaml.go
26
yaml.go
@ -17,7 +17,20 @@ var inputJSON = false
|
||||
var outputToJSON = false
|
||||
|
||||
func main() {
|
||||
var cmdRead = &cobra.Command{
|
||||
var cmdRead = createReadCmd()
|
||||
var cmdWrite = createWriteCmd()
|
||||
|
||||
var rootCmd = &cobra.Command{Use: "yaml"}
|
||||
rootCmd.PersistentFlags().BoolVarP(&trimOutput, "trim", "t", true, "trim yaml output")
|
||||
rootCmd.PersistentFlags().BoolVarP(&outputToJSON, "tojson", "j", false, "output as json")
|
||||
rootCmd.PersistentFlags().BoolVarP(&inputJSON, "fromjson", "J", false, "input as json")
|
||||
|
||||
rootCmd.AddCommand(cmdRead, cmdWrite)
|
||||
rootCmd.Execute()
|
||||
}
|
||||
|
||||
func createReadCmd() *cobra.Command {
|
||||
return &cobra.Command{
|
||||
Use: "read [yaml_file] [path]",
|
||||
Aliases: []string{"r"},
|
||||
Short: "yaml r sample.yaml a.b.c",
|
||||
@ -31,7 +44,9 @@ yaml r things.yaml a.array[*].blah
|
||||
Long: "Outputs the value of the given path in the yaml file to STDOUT",
|
||||
Run: readProperty,
|
||||
}
|
||||
}
|
||||
|
||||
func createWriteCmd() *cobra.Command {
|
||||
var cmdWrite = &cobra.Command{
|
||||
Use: "write [yaml_file] [path] [value]",
|
||||
Aliases: []string{"w"},
|
||||
@ -58,14 +73,7 @@ a.b.e:
|
||||
}
|
||||
cmdWrite.PersistentFlags().BoolVarP(&writeInplace, "inplace", "i", false, "update the yaml file inplace")
|
||||
cmdWrite.PersistentFlags().StringVarP(&writeScript, "script", "s", "", "yaml script for updating yaml")
|
||||
|
||||
var rootCmd = &cobra.Command{Use: "yaml"}
|
||||
rootCmd.PersistentFlags().BoolVarP(&trimOutput, "trim", "t", true, "trim yaml output")
|
||||
rootCmd.PersistentFlags().BoolVarP(&outputToJSON, "tojson", "j", false, "output as json")
|
||||
rootCmd.PersistentFlags().BoolVarP(&inputJSON, "fromjson", "J", false, "input as json")
|
||||
|
||||
rootCmd.AddCommand(cmdRead, cmdWrite)
|
||||
rootCmd.Execute()
|
||||
return cmdWrite
|
||||
}
|
||||
|
||||
func readProperty(cmd *cobra.Command, args []string) {
|
||||
|
Loading…
Reference in New Issue
Block a user