-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (68 loc) · 1.97 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
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
)
var (
cSrc string
cTar string
cPkg string
cGit bool
cOver bool
cMode string
RunDir, _ = filepath.Abs(filepath.Dir(os.Args[0]))
z7a = filepath.Join(RunDir, "7z")
LogPath = "pkm.log"
)
func main() {
flag.StringVar(&cMode, "M", "P", "[P]ackMode,[I]nstallMode,[L]istMode\n DEFAULT: P(PackMode)")
flag.StringVar(&cSrc, "S", "", "InstallMode: path of where store package.7z \n PackMode: where package src exists(EG: %GOPATH%\\src)\n ListMode: package src path (EG: %GOPATH%\\src)")
flag.StringVar(&cTar, "T", "", "InstallMode: path of package to install \n PackMode: path of where to store package.7z \n DEFAULT: same as -S")
flag.StringVar(&cPkg, "P", "", "InstallMode and ListMode ONLY: Package full name ")
flag.BoolVar(&cGit, "C", false, "PackMode ONLY: Remove .git folder \n DEFAULT: false")
flag.BoolVar(&cOver, "J", false, "PackMode and ListMode ONLY:\n PackMode:Overwrite Package.7z\n ListMode: List sub package depends \n DEFAULT: false")
flag.Parse()
switch {
case len(cSrc) == 0:
flag.Usage()
return
case cMode != "P" && cMode != "I" && cMode != "L":
fmt.Println("Must Define -M P|I|L (default P)")
flag.Usage()
return
case len(cSrc) == 0:
fmt.Println("Must Define -S")
flag.Usage()
return
case cMode == "I" && len(cPkg) == 0:
fmt.Println("Must Define -P PACKAGENAME when use InstallMode")
flag.Usage()
return
case cMode == "L" && len(cPkg) == 0:
fmt.Println("Must Define -P PACKAGENAME when use ListMode")
flag.Usage()
return
}
if len(cTar) == 0 {
cTar = cSrc
}
if FileExist(LogPath) {
os.Remove(LogPath)
}
Logf, er := os.Create(LogPath)
if er != nil {
fmt.Println("Create logfile error:", er)
os.Exit(1)
}
Logf.Close()
switch cMode {
case "I":
InstallPackage(cSrc, cTar, cPkg)
case "P":
PackPackage(cSrc, cTar, cGit, cOver)
case "L":
DepCheck(cPkg, cSrc, cOver)
}
}