aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2019-08-02 15:07:53 +0200
committerOndrej Fabry <ofabry@cisco.com>2019-08-02 15:07:53 +0200
commitca6003af1a7e1adb7d45879c2d5038bc05c2bb1a (patch)
tree97a3620b0fc5c7a0ee032fe7d12d37b6303cfb01 /cmd
parent639870b5083a1e66f4584ec7a5f30492fcdb7168 (diff)
Migrate to modules, refactor Makefile and use Travis for CI
- migrate to Go modules and remove vendor - refactor Makefile - add version package and store version - split extras from the rest - use travis for CI Change-Id: I81b35220653b0f7c9a0fcdd4c527d691ec1e96c1 Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/binapi-generator/main.go36
1 files changed, 31 insertions, 5 deletions
diff --git a/cmd/binapi-generator/main.go b/cmd/binapi-generator/main.go
index d46001d..7a43875 100644
--- a/cmd/binapi-generator/main.go
+++ b/cmd/binapi-generator/main.go
@@ -27,6 +27,8 @@ import (
"github.com/bennyscetbun/jsongo"
"github.com/sirupsen/logrus"
+
+ "git.fd.io/govpp.git/version"
)
var (
@@ -40,16 +42,40 @@ var (
includeBinapiNames = flag.Bool("include-binapi-names", false, "Include binary API names in struct tag.")
continueOnError = flag.Bool("continue-onerror", false, "Continue with next file on error.")
+ debugMode = flag.Bool("debug", os.Getenv("GOVPP_DEBUG") != "", "Enable debug mode.")
- debug = flag.Bool("debug", debugMode, "Enable debug mode.")
+ printVersion = flag.Bool("version", false, "Prints current version and exits.")
)
-var debugMode = os.Getenv("DEBUG_BINAPI_GENERATOR") != ""
-
func main() {
flag.Parse()
- if *debug {
+
+ if flag.NArg() > 1 {
+ flag.Usage()
+ os.Exit(1)
+ }
+
+ if flag.NArg() > 0 {
+ switch cmd := flag.Arg(0); cmd {
+ case "version":
+ fmt.Fprintln(os.Stdout, version.Verbose())
+ os.Exit(0)
+
+ default:
+ fmt.Fprintf(os.Stderr, "unknown command: %s\n", cmd)
+ flag.Usage()
+ os.Exit(2)
+ }
+ }
+
+ if *printVersion {
+ fmt.Fprintln(os.Stdout, version.Info())
+ os.Exit(0)
+ }
+
+ if *debugMode {
logrus.SetLevel(logrus.DebugLevel)
+ logrus.Info("debug mode enabled")
}
if err := run(*theInputFile, *theInputDir, *theOutputDir, *continueOnError); err != nil {
@@ -185,7 +211,7 @@ func generateFromFile(inputFile, outputDir string) error {
}
func logf(f string, v ...interface{}) {
- if *debug {
+ if *debugMode {
logrus.Debugf(f, v...)
}
}