github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/util/codegen/generate.go (about)

     1  // +build ignore
     2  
     3  package main
     4  
     5  import (
     6  	"fmt"
     7  	"os"
     8  	"text/template"
     9  
    10  	"code.cloudfoundry.org/cli/util/codegen"
    11  )
    12  
    13  func main() {
    14  	entity := os.Args[1]
    15  	templatePath := os.Args[2]
    16  	outputPath := os.Args[3]
    17  
    18  	template, err := template.ParseFiles(templatePath)
    19  	if err != nil {
    20  		panic(err)
    21  	}
    22  
    23  	outputFile, err := os.Create(outputPath)
    24  	defer outputFile.Close()
    25  	if err != nil {
    26  		panic(err)
    27  	}
    28  
    29  	fmt.Printf("generating %s from %s\n", outputPath, templatePath)
    30  
    31  	fmt.Fprintf(outputFile, "// generated from %s\n\n", templatePath)
    32  
    33  	templateInput := codegen.NewTemplateInput(entity)
    34  	err = template.Execute(outputFile, templateInput)
    35  	if err != nil {
    36  		panic(err)
    37  	}
    38  }