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
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