-
Notifications
You must be signed in to change notification settings - Fork 19
/
main.go
56 lines (48 loc) · 1.27 KB
/
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
package main
import (
"context"
"fmt"
"log"
"net/http"
_ "net/http/pprof"
"os"
"runtime"
"cdr.dev/coder-cli/internal/cmd"
"cdr.dev/coder-cli/internal/version"
"cdr.dev/coder-cli/internal/x/xterminal"
"cdr.dev/coder-cli/pkg/clog"
)
func main() {
ctx, cancel := context.WithCancel(context.Background())
// If requested, spin up the pprof webserver.
if os.Getenv("PPROF") != "" {
go func() {
log.Println(http.ListenAndServe("localhost:6060", nil))
}()
}
restoreTerminal := func() {}
// Janky, but SSH on windows sets the output to raw.
// If we set it ourselves, SSH fails because the FD isn't found.
if len(os.Args) >= 2 && os.Args[1] != "tunnel" {
state, err := xterminal.MakeOutputRaw(os.Stdout.Fd())
if err != nil {
clog.Log(clog.Fatal(fmt.Sprintf("set output to raw: %s", err)))
cancel()
os.Exit(1)
}
restoreTerminal = func() {
// Best effort. Would result in broken terminal on window but nothing we can do about it.
_ = xterminal.Restore(os.Stdout.Fd(), state)
}
}
app := cmd.Make()
app.Version = fmt.Sprintf("%s %s %s/%s", version.Version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
if err := app.ExecuteContext(ctx); err != nil {
clog.Log(err)
cancel()
restoreTerminal()
os.Exit(1)
}
cancel()
restoreTerminal()
}