Skip to content

Commit

Permalink
[Fix]: Convert init from function to simple execution script
Browse files Browse the repository at this point in the history
- Initialization is never call as it should be a simple execution script and not a function
  • Loading branch information
webalexeu authored Jun 4, 2024
1 parent 8e42aff commit 6b68574
Showing 1 changed file with 20 additions and 27 deletions.
47 changes: 20 additions & 27 deletions src/init/Initialize-PSWinBGP.ps1
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
function Initialize-PSWinBGP {
<#
.SYNOPSIS
Initialize-PSWinBGP
.DESCRIPTION
Initialize-PSWinBGP
#>
Register-ArgumentCompleter `
-CommandName Start-WinBGPRoute, Stop-WinBGPRoute, Start-WinBGPRouteMaintenance, Stop-WinBGPRouteMaintenance `
-ParameterName RouteName -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
# Define paramaters to $null to avoid syntax errors
$null = $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters
# Initializing PSWinBGP (Command completer is used by some public functions)
Register-ArgumentCompleter `
-CommandName Start-WinBGPRoute, Stop-WinBGPRoute, Start-WinBGPRouteMaintenance, Stop-WinBGPRouteMaintenance `
-ParameterName RouteName -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters)
# Define paramaters to $null to avoid syntax errors
$null = $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, `
"$(if ($_.ComputerName){"ComputerName: '$($_.ComputerName)' - RouteName: '$($_.Name)'"}else{$_.Name})", `
"ParameterValue", `
"$(if ($_.ComputerName){"ComputerName: '$($_.ComputerName)' - "})Network: '$($_.Network)' - Status: '$($_.Status)'"
}
# 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, `
"$(if ($_.ComputerName){"ComputerName: '$($_.ComputerName)' - RouteName: '$($_.Name)'"}else{$_.Name})", `
"ParameterValue", `
"$(if ($_.ComputerName){"ComputerName: '$($_.ComputerName)' - "})Network: '$($_.Network)' - Status: '$($_.Status)'"
}
}

0 comments on commit 6b68574

Please sign in to comment.