-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
70 lines (63 loc) · 1.67 KB
/
Copy pathmain.go
File metadata and controls
70 lines (63 loc) · 1.67 KB
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
package main
import (
"context"
"flag"
"fmt"
"os"
"runtime/debug"
"github.com/google/subcommands"
"github.com/uji/slack-wait/cmd"
)
// Build information injected via -ldflags by GoReleaser.
var (
version = "dev"
commit = "none"
date = "unknown"
)
// versionInfo returns build information, falling back to the embedded module
// metadata (set by `go install module@version`) when ldflags were not provided.
func versionInfo() (v, c, d string) {
v, c, d = version, commit, date
if v != "dev" {
return v, c, d
}
info, ok := debug.ReadBuildInfo()
if !ok {
return v, c, d
}
if info.Main.Version != "" && info.Main.Version != "(devel)" {
v = info.Main.Version
}
for _, s := range info.Settings {
switch s.Key {
case "vcs.revision":
c = s.Value
case "vcs.time":
d = s.Value
}
}
return v, c, d
}
func main() {
if len(os.Args) >= 2 && (os.Args[1] == "version" || os.Args[1] == "--version" || os.Args[1] == "-v") {
v, c, d := versionInfo()
fmt.Printf("slack-wait %s (commit %s, built %s)\n", v, c, d)
os.Exit(0)
}
if len(os.Args) >= 2 && (os.Args[1] == "login" || os.Args[1] == "logout") {
subcommands.Register(&cmd.LoginCommand{}, "")
subcommands.Register(&cmd.LogoutCommand{}, "")
flag.Parse()
os.Exit(int(subcommands.Execute(context.Background())))
}
w := &cmd.WaitCommand{}
f := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
w.SetFlags(f)
f.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
f.PrintDefaults()
fmt.Fprintf(os.Stderr, "\nSubcommands:\n login\tauthenticate via browser (PKCE)\n logout\tremove stored token\n")
}
f.Parse(os.Args[1:]) //nolint:errcheck
os.Exit(int(w.Execute(context.Background(), f)))
}