mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
parent
f37a36aad1
commit
b1c427abaa
|
@ -96,20 +96,24 @@ func (a *az) init(props Properties, env Environment) {
|
|||
a.env = env
|
||||
}
|
||||
|
||||
func (a *az) getFileContentWithoutBom(file string) string {
|
||||
const ByteOrderMark = "\ufeff"
|
||||
file = filepath.Join(a.env.homeDir(), file)
|
||||
config := a.env.getFileContent(file)
|
||||
return strings.TrimLeft(config, ByteOrderMark)
|
||||
}
|
||||
|
||||
func (a *az) enabled() bool {
|
||||
return a.getAzureProfile() || a.getAzureRmContext()
|
||||
}
|
||||
|
||||
func (a *az) getFileContentWithoutBom(file string) string {
|
||||
azFolder := ".azure"
|
||||
if a.env.getRuntimeGOOS() == linuxPlatform {
|
||||
azFolder = ".Azure"
|
||||
}
|
||||
file = filepath.Join(a.env.homeDir(), azFolder, file)
|
||||
config := a.env.getFileContent(file)
|
||||
const ByteOrderMark = "\ufeff"
|
||||
return strings.TrimLeft(config, ByteOrderMark)
|
||||
}
|
||||
|
||||
func (a *az) getAzureProfile() bool {
|
||||
var content string
|
||||
if content = a.getFileContentWithoutBom(".azure/azureProfile.json"); len(content) == 0 {
|
||||
if content = a.getFileContentWithoutBom("azureProfile.json"); len(content) == 0 {
|
||||
return false
|
||||
}
|
||||
var config AzureConfig
|
||||
|
@ -127,7 +131,7 @@ func (a *az) getAzureProfile() bool {
|
|||
|
||||
func (a *az) getAzureRmContext() bool {
|
||||
var content string
|
||||
if content = a.getFileContentWithoutBom(".azure/AzureRmContext.json"); len(content) == 0 {
|
||||
if content = a.getFileContentWithoutBom("AzureRmContext.json"); len(content) == 0 {
|
||||
return false
|
||||
}
|
||||
var config AzurePowerShellConfig
|
||||
|
|
|
@ -57,8 +57,9 @@ func TestAzSegment(t *testing.T) {
|
|||
content, _ := ioutil.ReadFile("./test/AzureRmContext.json")
|
||||
azureRmContext = string(content)
|
||||
}
|
||||
env.On("getFileContent", filepath.Join(home, ".azure/azureProfile.json")).Return(azureProfile)
|
||||
env.On("getFileContent", filepath.Join(home, ".azure/AzureRmContext.json")).Return(azureRmContext)
|
||||
env.On("getRuntimeGOOS", nil).Return(linuxPlatform)
|
||||
env.On("getFileContent", filepath.Join(home, ".Azure", "azureProfile.json")).Return(azureProfile)
|
||||
env.On("getFileContent", filepath.Join(home, ".Azure", "AzureRmContext.json")).Return(azureRmContext)
|
||||
env.onTemplate()
|
||||
props := properties{
|
||||
SegmentTemplate: tc.Template,
|
||||
|
|
Loading…
Reference in a new issue