-
Notifications
You must be signed in to change notification settings - Fork 2
/
di.go
52 lines (40 loc) · 1.16 KB
/
di.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
package supportscolor
import (
"os"
"runtime"
hasflag "github.com/jwalton/go-supportscolor/pkg/hasFlag"
"golang.org/x/term"
)
type environment interface {
LookupEnv(name string) (string, bool)
Getenv(name string) string
HasFlag(name string) bool
IsTerminal(fd int) bool
getWindowsVersion() (majorVersion, minorVersion, buildNumber uint32)
osEnableColor() bool
getGOOS() string
}
type defaultEnvironmentType struct{}
func (*defaultEnvironmentType) LookupEnv(name string) (string, bool) {
return os.LookupEnv(name)
}
func (*defaultEnvironmentType) Getenv(name string) string {
return os.Getenv(name)
}
func (*defaultEnvironmentType) HasFlag(flag string) bool {
return hasflag.HasFlag(flag)
}
func (*defaultEnvironmentType) IsTerminal(fd int) bool {
// TODO: Replace with github.com/mattn/go-isatty?
return term.IsTerminal(int(fd))
}
func (*defaultEnvironmentType) getWindowsVersion() (majorVersion, minorVersion, buildNumber uint32) {
return getWindowsVersion()
}
func (*defaultEnvironmentType) osEnableColor() bool {
return enableColor()
}
func (*defaultEnvironmentType) getGOOS() string {
return runtime.GOOS
}
var defaultEnvironment = defaultEnvironmentType{}