github.com/tenntenn/testtime@v0.2.3-0.20221118081726-55bcd1f05226/cmd/testtime/testtime.go (about)

     1  package main
     2  
     3  import (
     4  	"flag"
     5  	"fmt"
     6  	"go/build"
     7  	"os"
     8  	"path/filepath"
     9  	"strings"
    10  )
    11  
    12  var (
    13  	flagDir    string
    14  	flagUpdate bool
    15  )
    16  
    17  func init() {
    18  	flag.StringVar(&flagDir, "dir", defaultDir(), "working directory for testtime")
    19  	flag.BoolVar(&flagUpdate, "u", false, "update exsiting files")
    20  }
    21  
    22  func main() {
    23  	flag.Parse()
    24  	overlay, err := createOverlay(flagUpdate, flagDir)
    25  	if err != nil {
    26  		fmt.Fprintln(os.Stderr, "Error:", err)
    27  		os.Exit(1)
    28  	}
    29  	fmt.Println(overlay)
    30  }
    31  
    32  func defaultDir() string {
    33  	if envGOPATH := os.Getenv("GOPATH"); envGOPATH != "" {
    34  		gopath := strings.Split(envGOPATH, string(os.PathListSeparator))
    35  		return filepath.Join(gopath[0], "pkg", "testtime")
    36  	}
    37  	return filepath.Join(build.Default.GOPATH, "pkg", "testtime")
    38  }