Skip to content

Commit

Permalink
Merge pull request #141 from maddieclayton/fixAC
Browse files Browse the repository at this point in the history
Fix argument completer
  • Loading branch information
Maddie Clayton authored Apr 12, 2019
2 parents 9d2910f + 2677bd1 commit 299bf24
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// ----------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters
Expand All @@ -25,10 +26,22 @@ public PSArgumentCompleterAttribute(params string[] argumentList) : base(CreateS

public static ScriptBlock CreateScriptBlock(string[] resourceTypes)
{
string scriptResourceTypeList = "'" + String.Join("' , '", resourceTypes) + "'";
List<string> outputResourceTypes = new List<string>();
foreach (string resourceType in resourceTypes)
{
if (resourceType.Contains(" "))
{
outputResourceTypes.Add("\'\'" + resourceType + "\'\'");
}
else
{
outputResourceTypes.Add(resourceType);
}
}
string scriptResourceTypeList = "'" + String.Join("' , '", outputResourceTypes) + "'";
string script = "param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)\n" +
String.Format("$values = {0}\n", scriptResourceTypeList) +
"$values | Where-Object { $_ -Like \"$wordToComplete*\" } | Sort-Object | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) }";
"$values | Where-Object { $_ -Like \"$wordToComplete*\" -or $_ -Like \"'$wordToComplete*\" } | Sort-Object | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) }";
ScriptBlock scriptBlock = ScriptBlock.Create(script);
return scriptBlock;
}
Expand Down

0 comments on commit 299bf24

Please sign in to comment.