Private/Write-FunctionCall.ps1


function Write-FunctionCall
{
    param(
        [Parameter(Mandatory=$true)]
        [string]$FunctionName,
        [Parameter(Mandatory=$true)]
        [hashtable]$ParamValues,
        [switch]$Newlines
    )

    [string[]]$switch_params = @((Get-Command "$FunctionName").Parameters.GetEnumerator() |
            Where-Object { $_.Value.ParameterType -eq [System.Management.Automation.SwitchParameter] } |
            Select-Object -expand Key
    )

    [string]$sep = " "
    if ($Newlines) {
        $sep = " ``" + [environment]::NewLine
    }

    [string]$param_str = [string]::Join($sep, ($ParamValues.GetEnumerator() | ForEach-Object {
                if ($_.Value)
                {
                    $v = $_.Value
                    if ($v -is [bool])
                    {
                        if ($switch_params -contains $_.Key)
                        {
                            $v = ":`$$v"
                        }
                        else
                        {
                            $v = " `$$v"
                        }
                    }
                    else  #if ($v -is [string])
                    {
                        $v = " '$v'"
                    }
                    return "-$($_.Key)$v"
                }
            }))

    return $FunctionName + $sep + $param_str
}