forked from JanDeDobbeleer/oh-my-posh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsegment_dotnet.go
58 lines (47 loc) · 1.19 KB
/
segment_dotnet.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
package main
import (
"errors"
)
type dotnet struct {
props *properties
env environmentInfo
activeVersion string
unsupportedVersion bool
}
const (
//UnsupportedDotnetVersionIcon is displayed when the dotnet version in
//the current folder isn't supported by the installed dotnet SDK set.
UnsupportedDotnetVersionIcon Property = "unsupported_version_icon"
)
func (d *dotnet) string() string {
if d.unsupportedVersion {
return d.props.getString(UnsupportedDotnetVersionIcon, "\u2327")
}
if d.props.getBool(DisplayVersion, true) {
return d.activeVersion
}
return ""
}
func (d *dotnet) init(props *properties, env environmentInfo) {
d.props = props
d.env = env
}
func (d *dotnet) enabled() bool {
if !d.env.hasCommand("dotnet") {
return false
}
output, err := d.env.runCommand("dotnet", "--version")
if err == nil {
d.activeVersion = output
return true
}
// Exit code 145 is a special indicator that dotnet
// ran, but the current project config settings specify
// use of an SDK that isn't installed.
var exerr *commandError
if errors.As(err, &exerr) && exerr.exitCode == 145 {
d.unsupportedVersion = true
return true
}
return false
}