jhoek / UncommonSense.CBreeze

C#/PowerShell API for the Dynamics NAV C/AL object text format
MIT License
6 stars 4 forks source link

Argument auto-completion for object #80

Closed jhoek closed 6 years ago

jhoek commented 7 years ago
Import-Module UncommonSense.CBreeze.Automation

function Test-ArgumentCompletion {
    param
    (
        [Parameter(Position=1)]
        [string]$MyArgument
    )

    Write-Host $MyArgument
}

$ArgumentCompletion = {
    param(
        $commandName, 
        $parameterName, 
        $wordToComplete, 
        $commandAst, 
        $fakeBoundParameter
    )

    [UncommonSense.CBreeze.Core.BaseApp+TableNames] | 
        Get-Member -static -MemberType Properties | 
        Select-Object -ExpandProperty Name |
        Where-Object { $_ -like "$wordToComplete*" }
}

Register-ArgumentCompleter `
    -CommandName Test-ArgumentCompletion `
    -ParameterName MyArgument `
    -ScriptBlock $ArgumentCompletion
jhoek commented 6 years ago

Something similar for field names would be difficult, since we'd need to offer only fields in the selected table, which differs per context.

jhoek commented 6 years ago

Make sure we're not mixing data types, e.g. DrillDownPageID and LookupPageID are integers. Looking up integers like this doesn't add much value.