From b97c1efcafff5fdbbfc4f59d7e03d9460a2703cb Mon Sep 17 00:00:00 2001 From: webalexeu <28548335+webalexeu@users.noreply.github.com> Date: Tue, 4 Jun 2024 00:16:20 +0200 Subject: [PATCH] [Fix]: Configuration variable not initialized --- src/PSWinBGP.psm1 | 43 ++++-------------------------------------- src/data/PSWinBGP.psd1 | 8 ++++++++ 2 files changed, 12 insertions(+), 39 deletions(-) create mode 100644 src/data/PSWinBGP.psd1 diff --git a/src/PSWinBGP.psm1 b/src/PSWinBGP.psm1 index ba65728..07f73f5 100644 --- a/src/PSWinBGP.psm1 +++ b/src/PSWinBGP.psm1 @@ -1,7 +1,8 @@ -# Dot source public/private functions +# Dot source init/public/private functions +$init = @(Get-ChildItem -Path (Join-Path -Path $PSScriptRoot -ChildPath 'Init/*.ps1') -Recurse -ErrorAction Stop) $public = @(Get-ChildItem -Path (Join-Path -Path $PSScriptRoot -ChildPath 'Public/*.ps1') -Recurse -ErrorAction Stop) $private = @(Get-ChildItem -Path (Join-Path -Path $PSScriptRoot -ChildPath 'Private/*.ps1') -Recurse -ErrorAction Stop) -foreach ($import in @($public + $private)) { +foreach ($import in @($init + $public + $private)) { try { . $import.FullName } catch { @@ -11,43 +12,7 @@ foreach ($import in @($public + $private)) { Export-ModuleMember -Function $public.Basename -# Route Argument Completer -$ArgumentCompleterBlock = { - param( - $commandName, - $parameterName, - $wordToComplete, - $commandAst, - $fakeBoundParameters - ) - - # Dynamically generate routes array - if ($FakeBoundParameters.ComputerName) { - [Array] $routes = (Get-WinBGPRoute -ComputerName $FakeBoundParameters.ComputerName) - } else { - [Array] $routes = (Get-WinBGPRoute) - } - # Return routes as arguments (IntelliSense) - $routes | ForEach-Object { - New-Object -Type System.Management.Automation.CompletionResult -ArgumentList - $_.Name, - #"$($_.ComputerName)_$($_.Name)", - "$(if ($_.ComputerName){"ComputerName: '$($_.ComputerName)' - RouteName: '$($_.Name)'"}else{$_.Name})", - "ParameterValue", - "$(if ($_.ComputerName){"ComputerName: '$($_.ComputerName)' - "})Network: '$($_.Network)' - Status: '$($_.Status)'" - } - # To review (to avoid syntax error) - $null = $commandName - $null = $parameterName - $null = $wordToComplete - $null = $commandAst -} -Register-ArgumentCompleter ` - -CommandName Start-WinBGPRoute, Stop-WinBGPRoute, Start-WinBGPRouteMaintenance, Stop-WinBGPRouteMaintenance ` - -ParameterName RouteName ` - -ScriptBlock $ArgumentCompleterBlock - -# Declare a module-level variable +# Declare a module-level variable (TO REVIEW, it's now part of data folder) $PSWinBGP = [ordered]@{ LocalhostApiPort = 8888 LocalhostApiProtocol = 'http' diff --git a/src/data/PSWinBGP.psd1 b/src/data/PSWinBGP.psd1 new file mode 100644 index 0000000..8024514 --- /dev/null +++ b/src/data/PSWinBGP.psd1 @@ -0,0 +1,8 @@ +@{ + LocalhostApiPort = 8888 + LocalhostApiProtocol = 'http' + LocalhostApiTimeout = 5 + ApiPort = 8888 + ApiProtocol = 'https' + ApiTimeout = 10 +}