From 7a9c4c0993b9f62d1902cceff357badd04c8bfb6 Mon Sep 17 00:00:00 2001 From: Szymon Osiecki Date: Tue, 3 Oct 2023 00:08:04 +0200 Subject: [PATCH] feat: InstallUtils v0.2.0 Join-Str function. --- modules/InstallUtils/Functions/common.ps1 | 40 +++++++++++++++++++++++ modules/InstallUtils/InstallUtils.psd1 | 3 +- modules/InstallUtils/InstallUtils.psm1 | 1 + 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/modules/InstallUtils/Functions/common.ps1 b/modules/InstallUtils/Functions/common.ps1 index 5db541b1..5d0ce565 100644 --- a/modules/InstallUtils/Functions/common.ps1 +++ b/modules/InstallUtils/Functions/common.ps1 @@ -44,6 +44,46 @@ function Invoke-CommandRetry { } until ($exit) } +function Join-Str { + [CmdletBinding()] + [OutputType([string])] + param ( + [Parameter(Mandatory, ValueFromPipeline = $true)] + [string[]]$InputObject, + + [string]$Separator = ' ', + + [Parameter(ParameterSetName = 'Single')] + [switch]$SingleQuote, + + [Parameter(ParameterSetName = 'Double')] + [switch]$DoubleQuote + ) + + begin { + # instantiate list to store quoted elements + $lst = [System.Collections.Generic.List[string]]::new() + # calculate quote char + $quote = if ($SingleQuote) { + "'" + } elseif ($DoubleQuote) { + '"' + } else { + '' + } + } + + process { + # quote input elements + $lst.Add("${quote}$_${quote}") + } + + end { + # return joined elements + return [string]::Join($Separator, $lst) + } +} + function Test-IsAdmin { $currentIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent() $principal = [System.Security.Principal.WindowsPrincipal]$currentIdentity diff --git a/modules/InstallUtils/InstallUtils.psd1 b/modules/InstallUtils/InstallUtils.psd1 index 1a5b4a69..88b64ba9 100644 --- a/modules/InstallUtils/InstallUtils.psd1 +++ b/modules/InstallUtils/InstallUtils.psd1 @@ -12,7 +12,7 @@ RootModule = 'InstallUtils.psm1' # Version number of this module. - ModuleVersion = '0.1.0' + ModuleVersion = '0.2.0' # Supported PSEditions CompatiblePSEditions = @('Core', 'Desk') @@ -72,6 +72,7 @@ FunctionsToExport = @( # common 'Invoke-CommandRetry' + 'Join-Str' 'Test-IsAdmin' 'Update-SessionEnvironmentPath' # git diff --git a/modules/InstallUtils/InstallUtils.psm1 b/modules/InstallUtils/InstallUtils.psm1 index a30da0b1..f2f2cdfe 100644 --- a/modules/InstallUtils/InstallUtils.psm1 +++ b/modules/InstallUtils/InstallUtils.psm1 @@ -7,6 +7,7 @@ $exportModuleMemberParams = @{ Function = @( # common 'Invoke-CommandRetry' + 'Join-Str' 'Test-IsAdmin' 'Update-SessionEnvironmentPath' # git