Public/Utilities/Get-EdenServiceCommands.ps1
function Get-EdenServiceCommands { <# .SYNOPSIS Lists and generates Eden commands. .DESCRIPTION Lists the Eden commands you can execute and generates local commands to implement the Eden command for a solution or service. .EXAMPLE PS> Get-EdenServiceCommands os PS> e-esc Returns a list of all Eden commands and indicates which ones have been implemented by the current service or solution. .EXAMPLE PS> Get-EdenServiceCommands -Groups os PS> e-esc -g Returns a list of all Eden command groups. #> [CmdletBinding()] param( # Filters the list of commands by the whether the Alias of the # command matches the string you provide. [Alias("fa")] [String] $FilterAlias, # Displays the list of files that are necessary to implement the # Eden command that are currently not found in the Eden directory # for the solution or service. [Alias("dm")] [Switch] $DisplayMissing, # Displays all of the scripts that must be implemented for # the Eden command. [Alias("df")] [Switch] $DisplayFiles, # Creates any missing scripts for implementing the Eden command. # Creates the file with a .seed.ps1 extension. You will need # to remove the ".seed" portion of the file name for the Eden # framework to call the script and recognize that you have # implemented the command. [Alias("sm")] [Switch] $SeedMissing, # Forces the Eden framework to overwrite any existing seed files # when the SeedMissing switch is provided. [Alias("f")] [Switch] $Force, # Filters the list to only show the groups of Eden commands. # This helps with determining the string value to pass to the # Alias parameter when you want to filter the list of commands to a # single group. [Alias("g")] [Switch] $Groups ) $commandsAndFiles = Get-EdenServiceCommandList $commandCount = ($commandsAndFiles | Select-Object {$_.Command} -Unique | Measure-Object).Count Write-Host "Supported | Alias | Command ($commandCount)" -ForegroundColor Blue # Filter the list of commands based on whether the start of the alias matches the string provided for the $FilterAlias (-fa) parameter. if($FilterAlias) { $commandsAndFiles = ($commandsAndFiles | Where-Object { $_.Alias.StartsWith($FilterAlias) }) } # Loop through the commands. foreach ($command in $commandsAndFiles) { # Check if the command has a duplicate alias to another command. if ($command.Command.Length -gt 0 -and ($commandsAndFiles | Where-Object {$_.Alias -eq $command.Alias -and $_.Command -ne $command.Command}).Count -gt 0) { Write-Host "DUPLICATE ALIAS: $($command.Alias)" -ForegroundColor Yellow } $missing = @() # keeps an array of the missing files. $displayFileList = @() # keeps an array of the files to display to the user. # If the command starts with 5 dashses it is a group entry. if ($command.Type -eq "Group") { Write-Host $command.Command -ForegroundColor Blue } elseif (!$Groups) { # If we are not asked to only display the groups. if (Get-Command $command.Command.Split()[0] -errorAction SilentlyContinue) { #if the command actuallys exists and is imported if ($command.Type -eq "Standard" -or $command.Type -eq "Coding" -or $command.Type -eq "Command") { # If the command is designed to call a local script. $file = "./Eden/$($command.Group -replace ' ', '/')/$($command.Command -replace 'Eden', '').ps1" $seedFile = "./Eden/$($command.Group -replace ' ', '/')/$($command.Command -replace 'Eden', '').seed.ps1" if ($command.Supported -ne "Yes" -and $SeedMissing) { # If the file is not found and the SeedMissing option was set to true then create a seed file. if ($command.Supported -ne "Seeded" -or $Force) { # Only create the seed file if it does not exist or the Force option was selected. if (!(Test-Path "./Eden/")) { # Create the Eden folder in case it is missing. New-Item -ItemType Directory -Path "./Eden" } if ($Force) { # Remove the existing file if force option was selected. Remove-Item -Path $seedFile } @" [CmdletBinding()] param( `$Settings, [String] `$LoggingPrefix ) Write-EdenInfo "Performing some action." `$LoggingPrefix # Perform the action here. Write-EdenInfo "Finished performing some action." `$LoggingPrefix "@ | Out-File (New-Item -Path $seedFile -Force) # Create the seed file. $command.Supported = "Seeded" } } if ($DisplayMissing -and $command.Supported -ne "Yes") { $missing += " | Missing File: $file" } # Build missing lines to print if DislpayMissing option set. if ($DisplayFiles) { $displayFileList += " | Dependency: $file" } # Build lines to print if DisplayFiles option set. } if ($command.Type -eq "Command" -and $command.Supported -ne "Yes") { # the the command can use other commands (default logic flow) then reset the supported command to true and the check if each default flow command is supported. foreach ($commandDependency in $command.Commands) { $commandSupported = ($commandsAndFiles | Where-Object {$_.Command -eq $commandDependency -and $_.Supported -eq $True }).Count -gt 0 if ($DisplayMissing -and !$commandSupported) { $missing += " | Missing Command: $commandDependency" } if ($DisplayFiles) { $displayFileList += " | Dependency: $commandDependency" } # Build lines to print if DisplayFiles option set. } } $color = switch ($command.Supported) { "Yes" {"Green"} "No" {"Red"} "Seeded" {"Yellow"} }; # Set color for printing. Write-Host "$($command.Supported.PadRight(9, ' ')) | $($command.Alias.PadRight(10," ")) | $($command.Command)" -ForegroundColor $color foreach($missingFile in $missing) { Write-Host $missingFile -ForegroundColor Red } foreach($displayFile in $displayFileList) { Write-Host $displayFile -ForegroundColor White } } else { # The command has not been implemented in the Eden module. Write-Host "Future | $($command.Alias.PadRight(10," ")) | $($command.Command)" -ForegroundColor Gray } } } } New-Alias ` -Name e-esc ` -Value Get-EdenServiceCommands ` -Force |