"flag"
"fmt"
"io/ioutil"
- "log"
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/bennyscetbun/jsongo"
+ "github.com/sirupsen/logrus"
)
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 logf(f string, v ...interface{}) {
- if *debug {
- log.Printf(f, v...)
- }
+var log = logrus.Logger{
+ Level: logrus.InfoLevel,
+ Formatter: &logrus.TextFormatter{},
+ Out: os.Stdout,
}
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")
return err
}
+ ctx.includeAPIVersionCrc = *includeAPIVer
+ ctx.includeComments = *includeComments
+
// read input file contents
ctx.inputData, err = readFile(inputFile)
if err != nil {
// count number of lines in generated output file
cmd = exec.Command("wc", "-l", ctx.outputFile)
if output, err := cmd.CombinedOutput(); err != nil {
- log.Printf("wc command failed: %v\n%s", err, string(output))
+ log.Warnf("wc command failed: %v\n%s", err, string(output))
} else {
logf("generated lines: %s", output)
}
return &root, nil
}
+
+func logf(f string, v ...interface{}) {
+ if *debug {
+ logrus.Debugf(f, v...)
+ }
+}