Skip to content

Fix argument completer #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 12, 2019
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