Skip to content

Commit 299bf24

Browse files
author
Maddie Clayton
authored
Merge pull request Azure#141 from maddieclayton/fixAC
Fix argument completer
2 parents 9d2910f + 2677bd1 commit 299bf24

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/ResourceManager/Version2016_09_01/ArgumentCompleters/PSArgumentCompleter.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using System;
16+
using System.Collections.Generic;
1617
using System.Management.Automation;
1718

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

2627
public static ScriptBlock CreateScriptBlock(string[] resourceTypes)
2728
{
28-
string scriptResourceTypeList = "'" + String.Join("' , '", resourceTypes) + "'";
29+
List<string> outputResourceTypes = new List<string>();
30+
foreach (string resourceType in resourceTypes)
31+
{
32+
if (resourceType.Contains(" "))
33+
{
34+
outputResourceTypes.Add("\'\'" + resourceType + "\'\'");
35+
}
36+
else
37+
{
38+
outputResourceTypes.Add(resourceType);
39+
}
40+
}
41+
string scriptResourceTypeList = "'" + String.Join("' , '", outputResourceTypes) + "'";
2942
string script = "param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)\n" +
3043
String.Format("$values = {0}\n", scriptResourceTypeList) +
31-
"$values | Where-Object { $_ -Like \"$wordToComplete*\" } | Sort-Object | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) }";
44+
"$values | Where-Object { $_ -Like \"$wordToComplete*\" -or $_ -Like \"'$wordToComplete*\" } | Sort-Object | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) }";
3245
ScriptBlock scriptBlock = ScriptBlock.Create(script);
3346
return scriptBlock;
3447
}

0 commit comments

Comments
 (0)