diff --git a/shell/agents/Microsoft.Azure.Agent/DataRetriever.cs b/shell/agents/Microsoft.Azure.Agent/DataRetriever.cs index 2e291b31..af6c820e 100644 --- a/shell/agents/Microsoft.Azure.Agent/DataRetriever.cs +++ b/shell/agents/Microsoft.Azure.Agent/DataRetriever.cs @@ -15,6 +15,7 @@ internal class DataRetriever : IDisposable private const string MetadataQueryTemplate = "{{\"command\":\"{0}\"}}"; private const string MetadataEndpoint = "https://cli-validation-tool-meta-qry.azurewebsites.net/api/command_metadata"; + private static string s_azPythonPath; private static readonly Dictionary s_azNamingRules; private static readonly ConcurrentDictionary s_azStaticDataCache; @@ -305,9 +306,28 @@ static DataRetriever() s_azNamingRules.Add(rule.AzPSCommand, rule); } + s_azPythonPath = GetAzCLIPythonPath(); s_azStaticDataCache = new(StringComparer.OrdinalIgnoreCase); } + /// + /// TODO: Need to support Linux and macOS. + /// + private static string GetAzCLIPythonPath() + { + if (OperatingSystem.IsWindows()) + { + const string AzWindowsPath = @"Microsoft SDKs\Azure\CLI2\python.exe"; + string x64Path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), AzWindowsPath); + string x86Path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), AzWindowsPath); + + if (File.Exists(x64Path)) { return x64Path; } + if (File.Exists(x86Path)) { return x86Path; } + } + + return null; + } + internal DataRetriever(ResponseData data, HttpClient httpClient) { _stop = false; @@ -476,7 +496,7 @@ private List GetArgValues(ArgumentPair pair) hasCompleter = param.HasCompleter; } - if (_stop || !hasCompleter) { return null; } + if (_stop || !hasCompleter || s_azPythonPath is null) { return null; } // Then, try to get dynamic argument values using AzCLI tab completion. string commandLine = $"{pair.Command} {pair.Parameter} "; @@ -490,7 +510,7 @@ private List GetArgValues(ArgumentPair pair) { StartInfo = new ProcessStartInfo() { - FileName = @"C:\Program Files\Microsoft SDKs\Azure\CLI2\python.exe", + FileName = s_azPythonPath, Arguments = "-Im azure.cli", UseShellExecute = false, RedirectStandardOutput = true,