-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
50 lines (39 loc) · 932 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
"strings"
"github.com/warehouse-13/got/template"
)
const (
suffix = "_test"
ext = ".go"
)
func main() {
var filename string
flag.StringVar(&filename, "name", "", "The name of the test file (without the '_test'). Default: current package name.")
flag.Parse()
if filename != "" {
filename = strings.ReplaceAll(filename, suffix, "")
filename = strings.ReplaceAll(filename, ext, "")
}
path, err := os.Getwd()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
packageName := filepath.Base(path)
if filename == "" {
filename = packageName
}
tmpl := template.Generate(packageName)
filename = fmt.Sprintf("%s%s%s", filename, suffix, ext)
if err := os.WriteFile(filename, tmpl, 0644); err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Printf("Dummy test file written to %s.\n", filename)
fmt.Println("Run `go mod tidy` to start using.")
}