Private/Get-OriAzBopExternalDependenciesParamBasedOnTags.ps1

<#
.SYNOPSIS
    Get module into Version param structure
 
.PARAMETER ModuleName
    Name of the module
 
.PARAMETER Tags
    Array of module tags
 
.PARAMETER TagPrefixTemplate
    Prefix of the tags
     
#>

function Get-OriAzBopExternalDependenciesParamBasedOnTags {
    [CmdLetBinding()]
    [OutputType([Hashtable])]
    param (        
        [Parameter(Mandatory = $true, HelpMessage = "Name of the module")]
        [string] $ModuleName,

        [Parameter(Mandatory = $true, HelpMessage = "Array of module tags")]
        [AllowEmptyCollection()]
        [String[]] $Tags, 

        [Parameter(Mandatory = $false, HelpMessage = "Tempalet of the tag prefix")]
        [string] $TagPrefixTemplate = 'ExternalModuleDependencies_{0}_{1}'
    )
    $ErrorActionPreference = 'Stop'    
    Write-Verbose -Message ("[ START: {0}:{1} (v.{2}) ]" -f $Local:MyInvocation.MyCommand.Source, $Local:MyInvocation.MyCommand.Name, $Local:MyInvocation.MyCommand.Version)
    foreach ($arg in $PSBoundParameters.GetEnumerator()) {
        if ([string]::IsNullOrEmpty($arg.Value)) {
            Write-Debug -Message ("[null] {0}: {1}" -f $arg.Key, $arg.Value) -ErrorAction SilentlyContinue 
        }
        else {
            Write-Debug -Message ("[{2}] {0}: {1}" -f $arg.Key, $arg.Value, $arg.Value.GetType().Name) -ErrorAction SilentlyContinue 
        }
    }

    [Hashtable] $NewInstallParam = @{Name = $ModuleName }

    # Get only tags releavant to this module
    [String] $SeachMask = $TagPrefixTemplate -f $ModuleName, '*'
    [String] $TagPrefix = $TagPrefixTemplate -f $ModuleName, ''
    [String[]] $relevantTags = $Tags | Where-Object { $_ -ilike $SeachMask } | Sort-Object -Unique

    # Get parameters relevant to the Module
    if ($relevantTags.Count -gt 0) {
        [String[]] $moduleInstallParam = $relevantTags.Substring($TagPrefix.Length)
    }

    # Try to parse each tag to get values for next processing
    foreach ($item in $moduleInstallParam) {
        [string[]] $paramArrray = $item -split '-', 2
        if (![string]::IsNullOrEmpty($paramArrray[0])) {
            switch ($paramArrray[0]) {
                'RequiredVersion' { $NewInstallParam += @{ RequiredVersion = [Version]$paramArrray[1] }; break }
                'MaximumVersion' { $NewInstallParam += @{ MaximumVersion = [Version]$paramArrray[1] }; break }
                'MinimumVersion' { $NewInstallParam += @{ MinimumVersion = [Version]$paramArrray[1] }; break }
                'Version' { $NewInstallParam += @{ Version = [Version]$paramArrray[1] }; break }
                'AllowPrerelease' { $NewInstallParam += @{ AllowPrerelease = [boolean]::Parse($paramArrray[1]) }; break }
                'Guid' { $NewInstallParam += @{ Guid = $paramArrray[1] }; break }
                'Prerelease' { $NewInstallParam += @{ Prerelease = $paramArrray[1] }; break }
                Default { throw "Unknown tag [$item] relevant to the Module $ModuleName" }
            }
        }
    }

    Write-Debug (ConvertTo-Json -InputObject $NewInstallParam)
    Write-Verbose -Message ("[ END: {0} ]" -f $Local:MyInvocation.MyCommand.Name)
    return $NewInstallParam
}