fix(az): do not use env var for module

resolves #2436
This commit is contained in:
Jan De Dobbeleer 2022-06-25 19:42:08 +02:00 committed by Jan De Dobbeleer
parent 233bda542e
commit c59c876b87
2 changed files with 15 additions and 12 deletions

View file

@ -15,8 +15,6 @@ type Az struct {
AzureSubscription AzureSubscription
Origin string Origin string
configDir string
} }
const ( const (
@ -103,11 +101,6 @@ func (a *Az) Init(props properties.Properties, env environment.Environment) {
func (a *Az) Enabled() bool { func (a *Az) Enabled() bool {
source := a.props.GetString(Source, firstMatch) source := a.props.GetString(Source, firstMatch)
var err error
a.configDir, err = a.ConfigDir()
if err != nil {
return false
}
switch source { switch source {
case firstMatch: case firstMatch:
return a.getCLISubscription() || a.getModuleSubscription() return a.getCLISubscription() || a.getModuleSubscription()
@ -127,7 +120,11 @@ func (a *Az) FileContentWithoutBom(file string) string {
func (a *Az) getCLISubscription() bool { func (a *Az) getCLISubscription() bool {
var content string var content string
profile := filepath.Join(a.configDir, "azureProfile.json") configDir, err := a.ConfigDir(true)
if err != nil {
return false
}
profile := filepath.Join(configDir, "azureProfile.json")
if content = a.FileContentWithoutBom(profile); len(content) == 0 { if content = a.FileContentWithoutBom(profile); len(content) == 0 {
return false return false
} }
@ -147,8 +144,12 @@ func (a *Az) getCLISubscription() bool {
func (a *Az) getModuleSubscription() bool { func (a *Az) getModuleSubscription() bool {
var content string var content string
configDir, err := a.ConfigDir(false)
if err != nil {
return false
}
profiles := []string{ profiles := []string{
filepath.Join(a.configDir, "AzureRmContext.json"), filepath.Join(configDir, "AzureRmContext.json"),
} }
for _, profile := range profiles { for _, profile := range profiles {
if content = a.FileContentWithoutBom(profile); len(content) != 0 { if content = a.FileContentWithoutBom(profile); len(content) != 0 {
@ -180,12 +181,14 @@ func (a *Az) getModuleSubscription() bool {
return true return true
} }
func (a *Az) ConfigDir() (string, error) { func (a *Az) ConfigDir(cli bool) (string, error) {
configDirs := []string{ configDirs := []string{
a.env.Getenv("AZURE_CONFIG_DIR"),
filepath.Join(a.env.Home(), ".azure"), filepath.Join(a.env.Home(), ".azure"),
filepath.Join(a.env.Home(), ".Azure"), filepath.Join(a.env.Home(), ".Azure"),
} }
if cli {
configDirs = append([]string{a.env.Getenv("AZURE_CONFIG_DIR")}, configDirs...)
}
for _, dir := range configDirs { for _, dir := range configDirs {
if len(dir) != 0 && a.env.HasFolder(dir) { if len(dir) != 0 && a.env.HasFolder(dir) {
return dir, nil return dir, nil

View file

@ -235,7 +235,7 @@ New-Module -Name "oh-my-posh-core" -ScriptBlock {
} else { } else {
$themes | ForEach-Object -Process { $themes | ForEach-Object -Process {
Write-Host "Theme: $(Get-FileHyperlink -uri $_.FullName -Name ($_.BaseName -replace '\.omp$', ''))`n" Write-Host "Theme: $(Get-FileHyperlink -uri $_.FullName -Name ($_.BaseName -replace '\.omp$', ''))`n"
@(Start-Utf8Process $script:OMPExecutable @("print", "primary", "--config=$($_.FullName)", "--pwd=$PWD", "--shell=pwsh")) @(Start-Utf8Process $script:OMPExecutable @("print", "primary", "--config=$($_.FullName)", "--pwd=$PWD", "--shell=::SHELL::"))
Write-Host "`n" Write-Host "`n"
} }
} }