github.com/goradd/got@v1.1.1/main.go (about)

     1  package main
     2  
     3  import (
     4  	"flag"
     5  	"fmt"
     6  	"os"
     7  	"strings"
     8  
     9  	"github.com/goradd/got/internal/got"
    10  )
    11  
    12  var args string // A neat little trick to directly test the main function. If we are testing, this will get set.
    13  
    14  func main() {
    15  	var outDir string
    16  	var typ string
    17  	var runImports bool
    18  	var includes string
    19  	var inputDirectory string
    20  	var verbose bool
    21  	var recursive bool
    22  	var force bool
    23  
    24  	if len(os.Args[1:]) == 0 || args == "testEmpty" {
    25  		fmt.Println("got processes got template files, turning them into go code to use in your application.")
    26  		fmt.Println("Usage: got [-o outDir] [-t fileType] [-i] [-I includeDirs] file1 [file2 ...] ")
    27  		fmt.Println("-o: send processed files to the given directory. Otherwise sends to the same directory that the template is in.")
    28  		fmt.Println("-t: process all files with this suffix in the current directory. Otherwise, specify specific files at the end.")
    29  		fmt.Println("-i: run goimports on the result files to automatically fix up the import statement and format the file. You will need goimports installed.")
    30  		fmt.Println("-I: the list of directories to search for include files, or files to prepend before every processed file. Files are searched in the order given, and first one found will be used.")
    31  		fmt.Println("-d: The directory to search for files if using the -t directive.")
    32  		fmt.Println("-v: Verbose. Prints information about the files that are being processed.")
    33  		fmt.Println("-r: Recursively processes directoreis. Must be used with -t, and optionally -d.")
    34  		fmt.Println("-f: Force processing a file even if output file is not older than input file.")
    35  		return
    36  	}
    37  
    38  	flag.StringVar(&outDir, "o", "", "Output directory")
    39  	flag.StringVar(&typ, "t", "", "Will process all files with this suffix in current directory, or the directory given by the -d directive.")
    40  	flag.BoolVar(&runImports, "i", false, "Run goimports on the file to automatically add your imports to the file. You will need to install goimports to do this.")
    41  	flag.StringVar(&includes, "I", "", "The list of directories to look in to find template include files.")
    42  	flag.StringVar(&inputDirectory, "d", "", "The directory to search for files if using the -t directive. Otherwise the current directory will be searched.")
    43  	flag.BoolVar(&verbose, "v", false, "Verbose. Prints information about the files that are being processed.")
    44  	flag.BoolVar(&recursive, "r", false, "Recursively processes directories. Must be used with -t, and optionally -d.")
    45  	flag.BoolVar(&force, "f", false, "Force processing a file even if output file is not older than input file.")
    46  
    47  	if args == "" {
    48  		flag.Parse() // regular run of program
    49  	} else {
    50  		// test run
    51  		flag.CommandLine.Parse(strings.Split(args, " "))
    52  	}
    53  	files := flag.Args()
    54  
    55  	if err := got.Run(outDir,
    56  		typ,
    57  		runImports,
    58  		includes,
    59  		inputDirectory,
    60  		files,
    61  		verbose,
    62  		recursive,
    63  		force); err != nil {
    64  		_, _ = fmt.Fprintf(os.Stderr, err.Error())
    65  		os.Exit(1)
    66  	}
    67  }