endjin-gists.psm1

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

$script:VendirVersion = '0.45.1'

# Since this repo is currently private, there is no sensible default that will be accessible
$script:DefaultGistMapUrl = $env:GISTS_MAP_URL ?? ''
$script:DefaultGistMapGitSource = @{
    url  = $env:GISTS_MAP_REPO ?? 'endjin/endjin-gists'
    ref  = $env:GISTS_MAP_REPO_REF ?? 'main'
    path = $env:GISTS_MAP_REPO_PATH ?? 'module/gist-map.yml'
}

# find all the functions that make-up this module
$functions = Get-ChildItem -Recurse $PSScriptRoot/functions -Include *.ps1 | `
                                Where-Object { $_ -notmatch ".Tests.ps1" }

# dot source the individual scripts that make-up this module
foreach ($function in ($functions)) { . $function.FullName }

# Load the completer script block definitions
. $PSScriptRoot/endjin-gists.completers.ps1

# Setup auto-completers
Register-ArgumentCompleter -CommandName Get-EndjinGist -ParameterName Group -ScriptBlock $groupCompleter
Register-ArgumentCompleter -CommandName Get-EndjinGist -ParameterName Name -ScriptBlock $nameCompleter
Register-ArgumentCompleter -CommandName Get-EndjinGists -ParameterName Group -ScriptBlock $groupCompleter
Register-ArgumentCompleter -CommandName Get-EndjinGists -ParameterName Name -ScriptBlock $nameCompleter

# export the non-private functions (by convention, private function scripts must begin with an '_' character)
Export-ModuleMember -Function ( $functions |
                                    ForEach-Object { (Get-Item $_).BaseName } |
                                        Where-Object { -not $_.StartsWith("_") }
                            ) `
                    -Alias @('gist', 'gists')