-
Notifications
You must be signed in to change notification settings - Fork 1
/
binpkg.go
47 lines (43 loc) · 991 Bytes
/
binpkg.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
// binpkg is a binary installer for Codechain secure packages.
package main
import (
"flag"
"fmt"
"os"
"github.com/frankbraun/binpkg/command"
)
func usage() {
cmd := os.Args[0]
fmt.Fprintf(os.Stderr, "Usage: %s download\n", cmd)
fmt.Fprintf(os.Stderr, " %s install [-p prefix]\n", cmd)
fmt.Fprintf(os.Stderr, " %s uninstall [-p prefix]\n", cmd)
fmt.Fprintf(os.Stderr, " %s generate bindir\n", cmd)
os.Exit(2)
}
func main() {
if len(os.Args) < 2 {
usage()
}
argv0 := os.Args[0] + " " + os.Args[1]
args := os.Args[2:]
var err error
switch os.Args[1] {
case "download":
err = command.Download(argv0, args...)
case "install":
err = command.Install(argv0, args...)
case "uninstall":
err = command.Uninstall(argv0, args...)
case "generate":
err = command.Generate(argv0, args...)
default:
usage()
}
if err != nil {
if err != flag.ErrHelp {
fmt.Fprintf(os.Stderr, "%s: error: %s\n", os.Args[0], err)
os.Exit(1)
}
os.Exit(2)
}
}