Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions shell/agents/Microsoft.Azure.Agent/DataRetriever.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, NamingRule> s_azNamingRules;
private static readonly ConcurrentDictionary<string, AzCLICommand> s_azStaticDataCache;

Expand Down Expand Up @@ -305,9 +306,28 @@ static DataRetriever()
s_azNamingRules.Add(rule.AzPSCommand, rule);
}

s_azPythonPath = GetAzCLIPythonPath();
s_azStaticDataCache = new(StringComparer.OrdinalIgnoreCase);
}

/// <summary>
/// TODO: Need to support Linux and macOS.
/// </summary>
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;
Expand Down Expand Up @@ -476,7 +496,7 @@ private List<string> 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} ";
Expand All @@ -490,7 +510,7 @@ private List<string> 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,
Expand Down