forked from Azure/azure-powershell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into bez/release
- Loading branch information
Showing
10 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...icrosoft.Azure.Commands.Profile.Test.ArgumentCompleterTests/TestEnvironmentCompleter.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"Names": {}, | ||
"Variables": { | ||
"SubscriptionId": "9e223dbe-3399-4e19-88eb-0975f02ac87f" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/Accounts/Accounts/Common/EnvironmentCompleterAttribute.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Microsoft.Azure.Commands.Common.Authentication.Abstractions; | ||
using Microsoft.Azure.Commands.Common.Authentication.Models; | ||
using Microsoft.Azure.Commands.ResourceManager.Common; | ||
using System.Linq; | ||
using System.Management.Automation; | ||
|
||
namespace Microsoft.Azure.Commands.Profile.Common | ||
{ | ||
/// <summary> | ||
/// This attribute will allow the user to autocomplete the values for valid Azure Environment names when applied to Environment related cmdlet parameters. | ||
/// </summary> | ||
public class EnvironmentCompleterAttribute : ArgumentCompleterAttribute | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of <see cref="EnvironmentCompleterAttribute" /> . | ||
/// </summary> | ||
public EnvironmentCompleterAttribute() : base(CreateScriptBlock()) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Returns an array of available Azure Environment names. | ||
/// </summary> | ||
/// <returns></returns> | ||
public static string[] GetEnvironments() | ||
{ | ||
var profileClient = new RMProfileClient(AzureRmProfileProvider.Instance.GetProfile<AzureRmProfile>()); | ||
return profileClient.ListEnvironments(null).Select(x => x.Name).ToArray(); | ||
} | ||
|
||
private static ScriptBlock CreateScriptBlock() | ||
{ | ||
string script = "param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)\n" + | ||
"$environments = [Microsoft.Azure.Commands.Profile.Common.EnvironmentCompleterAttribute]::GetEnvironments()\n" + | ||
"$environments | Where-Object { $_ -Like \"$wordToComplete*\" } | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) }"; | ||
ScriptBlock scriptBlock = ScriptBlock.Create(script); | ||
return scriptBlock; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters