-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (51 loc) · 1.17 KB
/
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
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"os"
"path/filepath"
"regexp"
wio "github.com/Maki-Daisuke/go-whole-in-one"
)
func isValidName(name string) bool {
re := regexp.MustCompile(`[^-(),.0-9=@A-Z[\]^_a-z{}~]`)
return len(name) > 0 && !re.MatchString(name)
}
func main() {
name := ""
if len(os.Args) > 1 {
name = os.Args[1]
} else {
cwd, err := os.Getwd()
if err != nil {
panic(err)
}
name = filepath.Base(cwd)
}
if !isValidName(name) {
fmt.Fprintf(os.Stderr, "Invalid command name: %s\n", name)
fmt.Fprintf(os.Stderr, "You can use only the following characters in command name: (),-.0-9=@A-Z[]^_a-z{}~\n")
os.Exit(1)
}
err := wio.WriteMainGo(name, "0.0.1")
if err != nil {
if os.IsExist(err) {
fmt.Fprintln(os.Stderr, `Initialization failed: main.go already exists. Run wio-init in an empty directory.`)
os.Exit(1)
} else {
panic(err)
}
}
err = wio.WritePackingList(name)
if err != nil {
if os.IsExist(err) {
fmt.Fprintln(os.Stderr, `Initialization failed: packing-list already exists. Run wio-init in an empty directory.`)
os.Exit(1)
} else {
panic(err)
}
}
err = wio.WritePackGo([]byte{}, "")
if err != nil {
panic(err)
}
}