github.com/vugu/vugu@v0.3.6-0.20240430171613-3f6f402e014b/cmd/vugugen/vugugen.go (about)

     1  // vugugen is a command line tool to convert .vugu files into Go source code.
     2  package main
     3  
     4  import (
     5  	"flag"
     6  	"log"
     7  	"path/filepath"
     8  
     9  	"github.com/vugu/vugu/gen"
    10  )
    11  
    12  // we basically just wrap ParserGoPKg
    13  func main() {
    14  
    15  	// vugugen path/to/package
    16  
    17  	var opts gen.ParserGoPkgOpts
    18  	flag.BoolVar(&opts.SkipGoMod, "skip-go-mod", false, "Do not try to create go.mod as needed")
    19  	flag.BoolVar(&opts.SkipMainGo, "skip-main", false, "Do not try to create main.go as needed")
    20  	flag.BoolVar(&opts.TinyGo, "tinygo", false, "Generate code intended for compilation under Tinygo")
    21  	flag.BoolVar(&opts.MergeSingle, "s", false, "Merge generated code for a package into a single file.")
    22  	recursive := flag.Bool("r", false, "Run recursively on specified path and subdirectories.")
    23  	flag.Parse()
    24  
    25  	args := flag.Args()
    26  
    27  	// default to current directory
    28  	if len(args) == 0 {
    29  		args = []string{"."}
    30  	}
    31  
    32  	for _, arg := range args {
    33  
    34  		pkgPath := arg
    35  		var err error
    36  		pkgPath, err = filepath.Abs(pkgPath)
    37  		if err != nil {
    38  			log.Fatal(err)
    39  		}
    40  
    41  		if *recursive {
    42  			err = gen.RunRecursive(pkgPath, &opts)
    43  		} else {
    44  			err = gen.Run(pkgPath, &opts)
    45  		}
    46  
    47  		if err != nil {
    48  			log.Fatal(err)
    49  		}
    50  
    51  	}
    52  
    53  }