-
Notifications
You must be signed in to change notification settings - Fork 0
/
xpm.go
81 lines (68 loc) · 1.28 KB
/
xpm.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
76
77
78
79
80
81
package main
import (
"flag"
"fmt"
"os"
"strings"
xpm "xpm_internal"
)
var _Version string
var (
hflag bool
vflag bool
prefix string
)
func initGlobal() {
_Version = "0.0.1"
}
func initFlags() {
flag.BoolVar(&hflag, "help", false, "show this help information")
flag.BoolVar(&hflag, "h", false, "")
flag.BoolVar(&vflag, "version", false, "show version and exit")
flag.BoolVar(&vflag, "v", false, "")
flag.StringVar(&prefix, "prefix", ".", "set `prefix` path for installation")
flag.StringVar(&prefix, "p", ".", "")
flag.Parse()
}
func usage() {
fmt.Fprintf(os.Stderr, `XqPackageManager version: xpm/%s
Usage: xpm [-hv] [-p prefix] install <package_name>[@version] [config]
Options:
`, _Version)
flag.PrintDefaults()
}
func main() {
initGlobal()
initFlags()
if hflag {
usage()
return
}
if vflag {
fmt.Fprintf(os.Stdout, "xpm version %s\n", _Version)
return
}
args := flag.Args()
if len(args) < 2 {
usage()
return
}
switch args[0] {
case "install":
var vers string
vlist := strings.SplitN(args[1], "@", 2)
if len(vlist) == 2 {
vers = vlist[1]
} else {
vers = "latest"
}
config := args[2:]
err := xpm.Install(vlist[0], vers, config, prefix)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
}
default:
usage()
return
}
}