Generator improvements and cleanup
[govpp.git] / cmd / binapi-generator / main.go
index b73a699..b3a131c 100644 (file)
@@ -30,27 +30,15 @@ import (
 )
 
 var (
-       inputFile       = flag.String("input-file", "", "Input JSON file.")
-       inputDir        = flag.String("input-dir", ".", "Input directory with JSON files.")
+       inputFile       = flag.String("input-file", "", "Input file with VPP API in JSON format.")
+       inputDir        = flag.String("input-dir", ".", "Input directory with VPP API files in JSON format.")
        outputDir       = flag.String("output-dir", ".", "Output directory where package folders will be generated.")
-       includeAPIVer   = flag.Bool("include-apiver", false, "Whether to include VlAPIVersion in generated file.")
-       debug           = flag.Bool("debug", false, "Turn on debug mode.")
-       continueOnError = flag.Bool("continue-onerror", false, "Wheter to continue with next file on error.")
+       includeAPIVer   = flag.Bool("include-apiver", false, "Include APIVersion constant for each module.")
+       includeComments = flag.Bool("include-comments", false, "Include JSON API source in comments for each object.")
+       continueOnError = flag.Bool("continue-onerror", false, "Continue with next file on error.")
+       debug           = flag.Bool("debug", false, "Enable debug mode.")
 )
 
-func init() {
-       flag.Parse()
-       if *debug {
-               logrus.SetLevel(logrus.DebugLevel)
-       }
-}
-
-func logf(f string, v ...interface{}) {
-       if *debug {
-               logrus.Debugf(f, v...)
-       }
-}
-
 var log = logrus.Logger{
        Level:     logrus.InfoLevel,
        Formatter: &logrus.TextFormatter{},
@@ -58,6 +46,11 @@ var log = logrus.Logger{
 }
 
 func main() {
+       flag.Parse()
+       if *debug {
+               logrus.SetLevel(logrus.DebugLevel)
+       }
+
        if *inputFile == "" && *inputDir == "" {
                fmt.Fprintln(os.Stderr, "ERROR: input-file or input-dir must be specified")
                os.Exit(1)
@@ -112,6 +105,9 @@ func generateFromFile(inputFile, outputDir string) error {
                return err
        }
 
+       ctx.includeAPIVersionCrc = *includeAPIVer
+       ctx.includeComments = *includeComments
+
        // read input file contents
        ctx.inputData, err = readFile(inputFile)
        if err != nil {
@@ -182,3 +178,9 @@ func parseJSON(inputData []byte) (*jsongo.JSONNode, error) {
 
        return &root, nil
 }
+
+func logf(f string, v ...interface{}) {
+       if *debug {
+               logrus.Debugf(f, v...)
+       }
+}