-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
57 lines (49 loc) · 985 Bytes
/
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
// cmd/gofile shows the platform string of Go executables
//
// cmd/gofile takes one argument, which is either program name or abosolute or
// relative path to an executable; when a program name is provided, it's looked up
// up in the $PATH.
//
// Example usage
//
// ~ $ gofile godoc
// darwin_amd64
package main
import (
"fmt"
"os"
"os/exec"
"github.com/rjeczalik/which"
)
func die(v interface{}) {
fmt.Fprintln(os.Stderr, v)
os.Exit(1)
}
const usage = `NAME:
gofile - shows the platform string of Go executables
USAGE:
gofile name|path
EXAMPLES:
gofile godoc
gofile ~/bin/godoc`
func ishelp(s string) bool {
return s == "-h" || s == "-help" || s == "help" || s == "--help" || s == "/?"
}
func main() {
if len(os.Args) != 2 {
die(usage)
}
if ishelp(os.Args[1]) {
fmt.Println(usage)
return
}
path, err := exec.LookPath(os.Args[1])
if err != nil {
die(err)
}
ex, err := which.NewExec(path)
if err != nil {
die(err)
}
fmt.Println(ex.Type)
}