From 2406041faa197799c7715f815cbd391a5c0e9ad3 Mon Sep 17 00:00:00 2001 From: Ondrej Fabry Date: Fri, 26 Jan 2018 15:08:15 +0100 Subject: Make including VlAPIVersion in generated file as opt-in Change-Id: I6ce52a539afe8af90858718a788dd310e735dff5 Signed-off-by: Ondrej Fabry --- cmd/binapi-generator/generator.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/cmd/binapi-generator/generator.go b/cmd/binapi-generator/generator.go index 94ee177..15f6164 100644 --- a/cmd/binapi-generator/generator.go +++ b/cmd/binapi-generator/generator.go @@ -32,6 +32,13 @@ import ( "github.com/bennyscetbun/jsongo" ) +var ( + inputFile = flag.String("input-file", "", "Input JSON file.") + inputDir = flag.String("input-dir", ".", "Input directory with JSON files.") + outputDir = flag.String("output-dir", ".", "Output directory where package folders will be generated.") + includeAPIVer = flag.Bool("include-apiver", false, "Wether to include VlAPIVersion in generated file.") +) + // MessageType represents the type of a VPP message. type messageType int @@ -60,9 +67,6 @@ type context struct { } func main() { - inputFile := flag.String("input-file", "", "Input JSON file.") - inputDir := flag.String("input-dir", ".", "Input directory with JSON files.") - outputDir := flag.String("output-dir", ".", "Output directory where package folders will be generated.") flag.Parse() if *inputFile == "" && *inputDir == "" { @@ -405,14 +409,14 @@ func generatePackageHeader(ctx *context, w io.Writer, rootNode *jsongo.JSONNode) fmt.Fprintln(w, "package "+ctx.packageName) fmt.Fprintln(w, "import \""+apiImportPath+"\"") - fmt.Fprintln(w) - fmt.Fprintln(w, "// VlApiVersion contains version of the API.") - vlAPIVersion := rootNode.Map("vl_api_version") - if vlAPIVersion != nil { - fmt.Fprintln(w, "const VlAPIVersion = ", vlAPIVersion.Get()) + + vlAPIVersion := rootNode.Map("vl_api_version").Get() + if *includeAPIVer { + fmt.Fprintln(w, "// VlApiVersion contains version of the API.") + fmt.Fprintln(w, "const VlAPIVersion = ", vlAPIVersion) + fmt.Fprintln(w) } - fmt.Fprintln(w) } // generateMessageComment generates comment for a message into provider writer -- cgit 1.2.3-korg