-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (50 loc) · 1017 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
58
59
60
61
62
63
64
65
66
package main
import (
"fmt"
"os"
"runtime/debug"
"github.com/dominikwinter/pno/cmd"
)
func main() {
const usage = `Usage of pno <command> [<args>]
commands:
gen Generate a personal number
val Validate a personal number
args:
-h Help
-V Version`
if len(os.Args) < 2 {
fmt.Fprintln(os.Stderr, usage)
os.Exit(1)
}
command, args := os.Args[1], os.Args[2:]
switch command {
case "-h":
fmt.Fprintln(os.Stderr, usage)
os.Exit(0)
case "-V":
info, ok := debug.ReadBuildInfo()
if !ok {
return
}
var revision string
var time string
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
revision = setting.Value
}
if setting.Key == "vcs.time" {
time = setting.Value
}
}
fmt.Fprintf(os.Stdout, "%s %s\n", revision, time)
os.Exit(0)
case "gen":
cmd.Gen(args)
case "val":
cmd.Val(args)
default:
fmt.Fprintf(os.Stderr, "Unrecognized command %s.\n\n%s\n", command, usage)
os.Exit(1)
}
}