mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 20:39:40 -08:00
36 lines
689 B
Go
36 lines
689 B
Go
|
package main
|
||
|
|
||
|
import "regexp"
|
||
|
|
||
|
type golang struct {
|
||
|
props *properties
|
||
|
env environmentInfo
|
||
|
golangVersion string
|
||
|
}
|
||
|
|
||
|
func (g *golang) string() string {
|
||
|
if g.props.getBool(DisplayVersion, true) {
|
||
|
return g.golangVersion
|
||
|
}
|
||
|
return ""
|
||
|
}
|
||
|
|
||
|
func (g *golang) init(props *properties, env environmentInfo) {
|
||
|
g.props = props
|
||
|
g.env = env
|
||
|
}
|
||
|
|
||
|
func (g *golang) enabled() bool {
|
||
|
if !g.env.hasFiles("*.go") {
|
||
|
return false
|
||
|
}
|
||
|
if !g.env.hasCommand("go") {
|
||
|
return false
|
||
|
}
|
||
|
versionInfo, _ := g.env.runCommand("go", "version")
|
||
|
r := regexp.MustCompile(`go(?P<version>[0-9]+.[0-9]+.[0-9]+)`)
|
||
|
values := groupDict(r, versionInfo)
|
||
|
g.golangVersion = values["version"]
|
||
|
return true
|
||
|
}
|