/
const.go
56 lines (49 loc) · 1.09 KB
/
const.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 client
import (
"context"
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"github.com/telepresenceio/telepresence/v2/pkg/dos"
)
const (
// APIVersion is the API version of the daemon and connector API.
APIVersion = 3
)
// DisplayVersion returns a printable version for `telepresence`.
func DisplayVersion() string {
return fmt.Sprintf("%s (api v%d)", Version(), APIVersion)
}
// GetExe returns the name of the running executable.
func GetExe(ctx context.Context) string {
// Figure out our executable
exeName, err := dos.Executable(ctx)
if err != nil {
panic(err)
}
return exeName
}
func IsDaemon() bool {
const fg = "-foreground"
a := os.Args
return len(a) > 1 && strings.HasSuffix(a[1], fg) || len(a) > 2 && strings.HasSuffix(a[2], fg) && a[1] == "help"
}
func ProcessName() string {
const fg = "-foreground"
a := os.Args
var pn string
switch {
case len(a) > 2 && a[1] == "help":
pn = a[2]
case len(a) > 1:
pn = a[1]
default:
pn = filepath.Base(a[0])
if runtime.GOOS == "windows" {
pn = strings.TrimSuffix(pn, ".exe")
}
}
return strings.TrimSuffix(pn, fg)
}