github.com/keysonZZZ/kmg@v0.0.0-20151121023212-05317bfd7d39/kmg/SubCommand/Yaml2Json.go.bak (about) 1 package command 2 3 /* 4 import ( 5 "flag" 6 7 "github.com/bronze1man/kmg/console" 8 "github.com/bronze1man/kmg/encoding/kmgYaml" 9 "github.com/bronze1man/kmg/kmgFile" 10 ) 11 12 type Yaml2Json struct { 13 inputPath *string 14 outputPath *string 15 } 16 17 func (command *Yaml2Json) GetNameConfig() *console.NameConfig { 18 return &console.NameConfig{Name: "Yaml2Json", 19 Short: "convert from yaml to json", 20 } 21 } 22 23 func (command *Yaml2Json) ConfigFlagSet(flag *flag.FlagSet) { 24 command.inputPath = flag.String("i", "", "input file path") 25 command.outputPath = flag.String("o", "", "output file path") 26 } 27 func (command *Yaml2Json) Execute(context *console.Context) error { 28 inputPath := *command.inputPath 29 outputPath := *command.outputPath 30 if inputPath == "" || outputPath == "" { 31 return kmgYaml.Yaml2JsonIo(context.Stdin, context.Stdout) 32 } 33 transform := &kmgFile.DirectoryFileTransform{ 34 InputExt: "yml", 35 OuputExt: "json", 36 Transform: kmgYaml.Yaml2JsonIo, 37 } 38 return transform.Run(inputPath, outputPath) 39 } 40 */