diff --git a/main.go b/main.go index ab4d76c..7215c67 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ import ( "github.com/drone/drone-yaml/yaml" "github.com/drone/drone-yaml/yaml/compiler" "github.com/drone/drone-yaml/yaml/compiler/transform" + "github.com/drone/drone-yaml/yaml/converter" "github.com/drone/drone-yaml/yaml/linter" "github.com/drone/drone-yaml/yaml/pretty" "github.com/drone/drone-yaml/yaml/signer" @@ -28,6 +29,10 @@ var ( formatSave = format.Flag("save", "save result to source").Short('s').Bool() formatFile = format.Arg("source", "source file location").Default(".drone.yml").File() + convert = kingpin.Command("convert", "convert the yaml file") + convertSave = convert.Flag("save", "save result to source").Short('s').Bool() + convertFile = convert.Arg("source", "source file location").Default(".drone.yml").File() + lint = kingpin.Command("lint", "lint the yaml file") lintPriv = lint.Flag("privileged", "privileged mode").Short('p').Bool() lintFile = lint.Arg("source", "source file location").Default(".drone.yml").File() @@ -50,6 +55,8 @@ func main() { switch kingpin.Parse() { case format.FullCommand(): kingpin.FatalIfError(runFormat(), "") + case convert.FullCommand(): + kingpin.FatalIfError(runConvert(), "") case lint.FullCommand(): kingpin.FatalIfError(runLint(), "") case sign.FullCommand(): @@ -78,6 +85,26 @@ func runFormat() error { return err } +func runConvert() error { + f := *convertFile + d, err := ioutil.ReadAll(f) + if err != nil { + return err + } + m := converter.Metadata{ + Filename: f.Name(), + } + b, err := converter.Convert(d, m) + if err != nil { + return err + } + if *formatSave { + return ioutil.WriteFile(f.Name(), b, 0644) + } + _, err = io.Copy(os.Stderr, bytes.NewReader(b)) + return err +} + func runLint() error { f := *lintFile m, err := yaml.Parse(f)