endjin-gists.completers.ps1

# <copyright file="endjin-gists.completers.ps1" company="Endjin Limited">
# Copyright (c) Endjin Limited. All rights reserved.
# </copyright>

#
# This file is expected to be dot-sourced by those that need to consume the definitions,
# and allows their definition to be shared between the real usage scenario and the
# associated tests.
#

$groupCompleter = {
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
    try {
        $map = _Get-GistMapData -ScriptRoot $PSScriptRoot -GistMapUrl $script:DefaultGistMapUrl -GistMapGitSource $script:DefaultGistMapGitSource
        if ($map) {
            $map.Keys | Where-Object { $_ -like "$wordToComplete*" }
        }
    }
    catch { }
}

$nameCompleter = {
    param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
    try {
        $map = _Get-GistMapData -ScriptRoot $PSScriptRoot -GistMapUrl $script:DefaultGistMapUrl -GistMapGitSource $script:DefaultGistMapGitSource
        if ($map) {
            $group = $fakeBoundParameters['Group']
            if ($group -and $map.ContainsKey($group)) {
                $map[$group] | ForEach-Object { $_.name } | Where-Object { $_ -like "$wordToComplete*" }
            }
        }
    }
    catch { }
}