From 53e5ec40fa50d4c628ae0071d1422efe0217092e Mon Sep 17 00:00:00 2001 From: maddieclayton Date: Fri, 12 Apr 2019 11:02:35 -0700 Subject: [PATCH] Fix argument completer --- .../ArgumentCompleters/PSArgumentCompleter.cs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/ResourceManager/Version2016_09_01/ArgumentCompleters/PSArgumentCompleter.cs b/src/ResourceManager/Version2016_09_01/ArgumentCompleters/PSArgumentCompleter.cs index 6f8822a01e..19d91b9864 100644 --- a/src/ResourceManager/Version2016_09_01/ArgumentCompleters/PSArgumentCompleter.cs +++ b/src/ResourceManager/Version2016_09_01/ArgumentCompleters/PSArgumentCompleter.cs @@ -13,6 +13,7 @@ // ---------------------------------------------------------------------------------- using System; +using System.Collections.Generic; using System.Management.Automation; namespace Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters @@ -25,10 +26,22 @@ public PSArgumentCompleterAttribute(params string[] argumentList) : base(CreateS public static ScriptBlock CreateScriptBlock(string[] resourceTypes) { - string scriptResourceTypeList = "'" + String.Join("' , '", resourceTypes) + "'"; + List outputResourceTypes = new List(); + 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; }