No Parameter Completion Support?

Aug 13, 2011 at 11:46 PM

We maintain a set of CLI scripts for administering our product.  I'd like to add parameter-completion support.  However, it looks like PowerTab only supports completing arguments, not parameters - is that right?  At the least, when I register a handler, like this:

Register-TabExpansion "fake" -Type "Command" {
	param ($Context, [ref]$TabExpansionHasOutput, [ref]$QuoteSpaces)

	# Return the possible parameters
	$TabExpansionHasOutput.Value = $true

It works fine in many cases:

"fake <TAB>" gives me the expected list.

"fake anyvalue<TAB>" yields the expected list, too ("anyvalue" is just discarded)

But on "fake -<TAB>", my handler is never called at all.

Any advice on how to support tab-expansion of parameters (not arguments) for a custom CLI?



Aug 23, 2011 at 7:26 AM
Edited Aug 23, 2011 at 7:26 AM

Apologies for the wait.  I don't have this documented yet, but the way to go about doing this is to register a "ParameterName" handler.  Here is an example that is already in PowerTab.


Register-TabExpansion powershell.exe -Type ParameterName {
    param($Context, $Parameter)
    $Parameters = "-Command","-EncodedCommand","-ExecutionPolicy","-File","-InputFormat","-NoExit","-NoLogo",
    $Parameters | Where-Object {$_ -like "$Parameter*"}


Basically it is just a function that is given a context object plus what the user typed (including the dash).  And you return the list of parameters that you want to display.

If you want to also have a handler that deals with values to any of those parameters, you need to register another type of handler called a "CommandInfo".  This shows a PowerTab a CommandInfo object like any PowerShell command would have.  Here is an example.


Function powershellexeparameters {

$PowershellCommandInfo = Get-Command powershellexeparameters
Register-TabExpansion powershell.exe -Type CommandInfo {
Aug 23, 2011 at 7:30 AM

Sweet.  Thanks for such a complete reply.  I'll try this immediately.