-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (61 loc) · 1.36 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package main
import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
"runtime"
)
const VERSION = "version 3.0.0 alpha (Mark III)"
type StringValue struct {
Value string
}
func (s *StringValue) Set(value string) error {
s.Value = value
return nil
}
// Implement the flag.Value interface
func (s *StringValue) String() string {
return fmt.Sprintf("%v", *s)
}
var Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of wiz:\n")
flag.PrintDefaults()
}
func main() {
parse()
flag.Usage = Usage
cmdInit := flag.Bool("init", false, "Create an empty Wiz repository in the current working directory")
cmdVersion := flag.Bool("version", false, "Prints current Wiz cmdVersion and exists")
flag.Parse()
if *cmdVersion {
printVersion()
os.Exit(0)
}
if *cmdInit {
createEmptyRepo()
os.Exit(0)
}
Usage()
}
func printVersion() {
fmt.Fprintf(os.Stdout, "wiz %s\n", VERSION)
fmt.Fprintf(os.Stdout, "%s on %s/%s (%d cores)\n", runtime.Version(), runtime.GOOS, runtime.GOARCH, runtime.NumCPU())
}
func createEmptyRepo() {
dir, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
dir = filepath.Join(dir, ".wiz")
_, err = os.Stat(dir)
if err != nil {
if !os.IsNotExist(err) {
log.Fatal(err)
}
} else {
log.Fatal("Repository already exist, cannot init non empty directory in", dir)
}
fmt.Fprintf(os.Stderr, "Initializing empty Wiz repository in %s\n", dir)
}