Croze.psm1
# Module created by Microsoft.PowerShell.Crescendo # Version: 1.1.0 # Schema: https://aka.ms/PowerShell/Crescendo/Schemas/2022-06 # Generated at: 01/28/2024 20:12:26 class PowerShellCustomFunctionAttribute : System.Attribute { [bool]$RequiresElevation [string]$Source PowerShellCustomFunctionAttribute() { $this.RequiresElevation = $false; $this.Source = "Microsoft.PowerShell.Crescendo" } PowerShellCustomFunctionAttribute([bool]$rElevation) { $this.RequiresElevation = $rElevation $this.Source = "Microsoft.PowerShell.Crescendo" } } # Returns available errors # Assumes that we are being called from within a script cmdlet when EmitAsError is used. function Pop-CrescendoNativeError { param ([switch]$EmitAsError) while ($__CrescendoNativeErrorQueue.Count -gt 0) { if ($EmitAsError) { $msg = $__CrescendoNativeErrorQueue.Dequeue() $er = [System.Management.Automation.ErrorRecord]::new([system.invalidoperationexception]::new($msg), $PSCmdlet.Name, "InvalidOperation", $msg) $PSCmdlet.WriteError($er) } else { $__CrescendoNativeErrorQueue.Dequeue() } } } # this is purposefully a filter rather than a function for streaming errors filter Push-CrescendoNativeError { if ($_ -is [System.Management.Automation.ErrorRecord]) { $__CrescendoNativeErrorQueue.Enqueue($_) } else { $_ } } function Get-HomebrewTap { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding()] param( ) BEGIN { $PSNativeCommandUseErrorActionPreference = $false $__CrescendoNativeErrorQueue = [System.Collections.Queue]::new() $__PARAMETERMAP = @{} $__outputHandlers = @{ Default = @{ StreamOutput = $False; Handler = { param ($output) if ($output) { $output | ForEach-Object { [PSCustomObject]@{ Name = $_ } } } } } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += 'tap' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Where-Object {!$__PARAMETERMAP[$_].ExcludeAsArgument}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { # if a transform is specified, use it and the construction of the values is up to the transform if($param.ArgumentTransform -ne '$args') { $transform = $param.ArgumentTransform if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } $__commandArgs += & $transform $value } else { $pFmt = "{0}{1}" # quote the strings if they have spaces if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } else { $transform = $param.ArgumentTransform } $__commandArgs += & $transform $value } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message "brew" $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("brew $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "brew")) { throw "Cannot find executable 'brew'" } if ( $__handlerInfo.StreamOutput ) { if ( $null -eq $__handler ) { & "brew" $__commandArgs } else { & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError | & $__handler } } else { $result = & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError & $__handler $result } } # be sure to let the user know if there are any errors Pop-CrescendoNativeError -EmitAsError } # end PROCESS <# .DESCRIPTION Return Homebrew taps #> } function Register-HomebrewTap { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding()] param( [Parameter(Mandatory=$true)] [string]$Name, [Parameter()] [string]$Location ) BEGIN { $PSNativeCommandUseErrorActionPreference = $false $__CrescendoNativeErrorQueue = [System.Collections.Queue]::new() $__PARAMETERMAP = @{ Name = @{ OriginalName = '' OriginalPosition = '0' Position = '2147483647' ParameterType = 'string' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } Location = @{ OriginalName = '' OriginalPosition = '0' Position = '2147483647' ParameterType = 'string' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } } $__outputHandlers = @{ Default = @{ StreamOutput = $False; Handler = { param ( $output ) # Clear the Crescendo stderr queue of Homebrew's abuse of stderr Pop-CrescendoNativeError | Out-Null } } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += 'tap' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Where-Object {!$__PARAMETERMAP[$_].ExcludeAsArgument}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { # if a transform is specified, use it and the construction of the values is up to the transform if($param.ArgumentTransform -ne '$args') { $transform = $param.ArgumentTransform if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } $__commandArgs += & $transform $value } else { $pFmt = "{0}{1}" # quote the strings if they have spaces if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } else { $transform = $param.ArgumentTransform } $__commandArgs += & $transform $value } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message "brew" $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("brew $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "brew")) { throw "Cannot find executable 'brew'" } if ( $__handlerInfo.StreamOutput ) { if ( $null -eq $__handler ) { & "brew" $__commandArgs } else { & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError | & $__handler } } else { $result = & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError & $__handler $result } } # be sure to let the user know if there are any errors Pop-CrescendoNativeError -EmitAsError } # end PROCESS <# .DESCRIPTION Register a new Homebrew tap .PARAMETER Name Source Name .PARAMETER Location Source Location #> } function Unregister-HomebrewTap { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding()] param( [Parameter(ValueFromPipelineByPropertyName=$true,Mandatory=$true)] [string]$Name ) BEGIN { $PSNativeCommandUseErrorActionPreference = $false $__CrescendoNativeErrorQueue = [System.Collections.Queue]::new() $__PARAMETERMAP = @{ Name = @{ OriginalName = '' OriginalPosition = '0' Position = '2147483647' ParameterType = 'string' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } } $__outputHandlers = @{ Default = @{ StreamOutput = $False; Handler = { param ( $output ) # Clear the Crescendo stderr queue of Homebrew's abuse of stderr Pop-CrescendoNativeError | Out-Null } } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += 'untap' $__commandArgs += '-f' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Where-Object {!$__PARAMETERMAP[$_].ExcludeAsArgument}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { # if a transform is specified, use it and the construction of the values is up to the transform if($param.ArgumentTransform -ne '$args') { $transform = $param.ArgumentTransform if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } $__commandArgs += & $transform $value } else { $pFmt = "{0}{1}" # quote the strings if they have spaces if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } else { $transform = $param.ArgumentTransform } $__commandArgs += & $transform $value } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message "brew" $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("brew $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "brew")) { throw "Cannot find executable 'brew'" } if ( $__handlerInfo.StreamOutput ) { if ( $null -eq $__handler ) { & "brew" $__commandArgs } else { & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError | & $__handler } } else { $result = & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError & $__handler $result } } # be sure to let the user know if there are any errors Pop-CrescendoNativeError -EmitAsError } # end PROCESS <# .DESCRIPTION Unregister an existing Homebrew tap .PARAMETER Name Source Name #> } function Install-HomebrewPackage { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding()] param( [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Formula')] [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Cask')] [string]$Name, [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Formula')] [switch]$Formula, [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Cask')] [switch]$Cask, [Parameter(ParameterSetName='Formula')] [Parameter(ParameterSetName='Cask')] [switch]$Force ) BEGIN { $PSNativeCommandUseErrorActionPreference = $false $__CrescendoNativeErrorQueue = [System.Collections.Queue]::new() $__PARAMETERMAP = @{ Name = @{ OriginalName = '' OriginalPosition = '0' Position = '2147483647' ParameterType = 'string' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } Formula = @{ OriginalName = '--formula' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } Cask = @{ OriginalName = '--cask' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } Force = @{ OriginalName = '--force' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } } $__outputHandlers = @{ Formula = @{ StreamOutput = $False; Handler = { param ( $output ) # Clear the Crescendo stderr queue of Homebrew's abuse of stderr Pop-CrescendoNativeError | Out-Null $output | Select-String '🍺(.+)/(?<name>.+)/(?<version>.+):' | ForEach-Object -MemberName Matches | ForEach-Object { $match = ($_.Groups | Where-Object Name -in 'name', 'version').Value [PSCustomObject]@{ Name = $match[0] Version = $match[1] } } } } Cask = @{ StreamOutput = $False; Handler = { param ( $output ) # Clear the Crescendo stderr queue of Homebrew's abuse of stderr Pop-CrescendoNativeError | Out-Null $output | Select-String '(?<name>\S+) was successfully' | ForEach-Object -MemberName Matches | ForEach-Object { $match = ($_.Groups | Where-Object Name -eq 'name').Value [PSCustomObject]@{ Name = $match } } } } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += 'install' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Where-Object {!$__PARAMETERMAP[$_].ExcludeAsArgument}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { # if a transform is specified, use it and the construction of the values is up to the transform if($param.ArgumentTransform -ne '$args') { $transform = $param.ArgumentTransform if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } $__commandArgs += & $transform $value } else { $pFmt = "{0}{1}" # quote the strings if they have spaces if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } else { $transform = $param.ArgumentTransform } $__commandArgs += & $transform $value } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message "brew" $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("brew $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "brew")) { throw "Cannot find executable 'brew'" } if ( $__handlerInfo.StreamOutput ) { if ( $null -eq $__handler ) { & "brew" $__commandArgs } else { & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError | & $__handler } } else { $result = & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError & $__handler $result } } # be sure to let the user know if there are any errors Pop-CrescendoNativeError -EmitAsError } # end PROCESS <# .DESCRIPTION Install a new package with Homebrew .PARAMETER Name Package Name .PARAMETER Formula Formula .PARAMETER Cask Cask .PARAMETER Force Force #> } function Get-HomebrewPackage { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding()] param( [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Formula')] [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Cask')] [string]$Name, [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Formula')] [switch]$Formula, [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Cask')] [switch]$Cask ) BEGIN { $PSNativeCommandUseErrorActionPreference = $false $__CrescendoNativeErrorQueue = [System.Collections.Queue]::new() $__PARAMETERMAP = @{ Name = @{ OriginalName = '' OriginalPosition = '0' Position = '2147483647' ParameterType = 'string' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } Formula = @{ OriginalName = '--formula' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } Cask = @{ OriginalName = '--cask' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } } $__outputHandlers = @{ Formula = @{ StreamOutput = $False; Handler = { param ( $output ) $output | Where-Object { $_ } | ConvertFrom-StringData -Delimiter ' ' | ForEach-Object { # Brew supports installing multiple versions side-by-side, but instead of listing them as separate rows, it puts multiple versions on the same row. # To present this package data in a way that's idiomatic to PowerShell, we need to list each version as a separate object: $_.GetEnumerator() | ForEach-Object { $name = $_.Name $_.Value -split ' ' | Select-Object -Property @{ Name = 'Name' Expression = { $name } }, @{ Name = 'Version' Expression = { $_ } }, @{ Name = 'Formula' Expression = { $true } } } } } } Cask = @{ StreamOutput = $False; Handler = { param ( $output ) $output | Where-Object { $_ } | ConvertFrom-StringData -Delimiter ' ' | ForEach-Object { # Brew supports installing multiple versions side-by-side, but instead of listing them as separate rows, it puts multiple versions on the same row. # To present this package data in a way that's idiomatic to PowerShell, we need to list each version as a separate object: $_.GetEnumerator() | ForEach-Object { $name = $_.Name $_.Value -split ' ' | Select-Object -Property @{ Name = 'Name' Expression = { $name } }, @{ Name = 'Version' Expression = { $_ } }, @{ Name = 'Cask' Expression = { $true } } } } } } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += 'list' $__commandArgs += '--versions' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Where-Object {!$__PARAMETERMAP[$_].ExcludeAsArgument}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { # if a transform is specified, use it and the construction of the values is up to the transform if($param.ArgumentTransform -ne '$args') { $transform = $param.ArgumentTransform if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } $__commandArgs += & $transform $value } else { $pFmt = "{0}{1}" # quote the strings if they have spaces if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } else { $transform = $param.ArgumentTransform } $__commandArgs += & $transform $value } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message "brew" $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("brew $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "brew")) { throw "Cannot find executable 'brew'" } if ( $__handlerInfo.StreamOutput ) { if ( $null -eq $__handler ) { & "brew" $__commandArgs } else { & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError | & $__handler } } else { $result = & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError & $__handler $result } } # be sure to let the user know if there are any errors Pop-CrescendoNativeError -EmitAsError } # end PROCESS <# .DESCRIPTION Get a list of installed Homebrew packages .PARAMETER Name Package Name .PARAMETER Formula Formula .PARAMETER Cask Cask #> } function Find-HomebrewPackage { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding()] param( [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Formula')] [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Cask')] [string]$Name, [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Formula')] [switch]$Formula, [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Cask')] [switch]$Cask ) BEGIN { $PSNativeCommandUseErrorActionPreference = $false $__CrescendoNativeErrorQueue = [System.Collections.Queue]::new() $__PARAMETERMAP = @{ Name = @{ OriginalName = '' OriginalPosition = '0' Position = '2147483647' ParameterType = 'string' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } Formula = @{ OriginalName = '--formula' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } Cask = @{ OriginalName = '--cask' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } } $__outputHandlers = @{ Formula = @{ StreamOutput = $False; Handler = { param ($output) $output | Where-Object {$_} | ForEach-Object { [PSCustomObject]@{ Name = $_ Formula = $true } } } } Cask = @{ StreamOutput = $False; Handler = { param ($output) $output | Where-Object {$_} | ForEach-Object { [PSCustomObject]@{ Name = $_ Cask = $true } } } } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += 'search' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Where-Object {!$__PARAMETERMAP[$_].ExcludeAsArgument}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { # if a transform is specified, use it and the construction of the values is up to the transform if($param.ArgumentTransform -ne '$args') { $transform = $param.ArgumentTransform if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } $__commandArgs += & $transform $value } else { $pFmt = "{0}{1}" # quote the strings if they have spaces if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } else { $transform = $param.ArgumentTransform } $__commandArgs += & $transform $value } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message "brew" $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("brew $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "brew")) { throw "Cannot find executable 'brew'" } if ( $__handlerInfo.StreamOutput ) { if ( $null -eq $__handler ) { & "brew" $__commandArgs } else { & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError | & $__handler } } else { $result = & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError & $__handler $result } } # be sure to let the user know if there are any errors Pop-CrescendoNativeError -EmitAsError } # end PROCESS <# .DESCRIPTION Find a list of available Homebrew packages .PARAMETER Name Package Name .PARAMETER Formula Formula .PARAMETER Cask Cask #> } function Update-HomebrewPackage { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding()] param( [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Formula')] [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Cask')] [string]$Name, [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Formula')] [switch]$Formula, [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Cask')] [switch]$Cask ) BEGIN { $PSNativeCommandUseErrorActionPreference = $false $__CrescendoNativeErrorQueue = [System.Collections.Queue]::new() $__PARAMETERMAP = @{ Name = @{ OriginalName = '' OriginalPosition = '0' Position = '2147483647' ParameterType = 'string' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } Formula = @{ OriginalName = '--formula' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } Cask = @{ OriginalName = '--cask' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } } $__outputHandlers = @{ Formula = @{ StreamOutput = $False; Handler = { param ( $output ) # Clear the Crescendo stderr queue of Homebrew's abuse of stderr Pop-CrescendoNativeError | Out-Null $output | Select-String '🍺(.+)/(?<name>.+)/(?<version>.+):' | ForEach-Object -MemberName Matches | ForEach-Object { $match = ($_.Groups | Where-Object Name -in 'name', 'version').Value [PSCustomObject]@{ Name = $match[0] Version = $match[1] } } } } Cask = @{ StreamOutput = $False; Handler = { param ( $output ) # Clear the Crescendo stderr queue of Homebrew's abuse of stderr Pop-CrescendoNativeError | Out-Null $output | Select-String '(?<name>\S+) was successfully' | ForEach-Object -MemberName Matches | ForEach-Object { $match = ($_.Groups | Where-Object Name -eq 'name').Value [PSCustomObject]@{ Name = $match } } } } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += 'upgrade' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Where-Object {!$__PARAMETERMAP[$_].ExcludeAsArgument}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { # if a transform is specified, use it and the construction of the values is up to the transform if($param.ArgumentTransform -ne '$args') { $transform = $param.ArgumentTransform if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } $__commandArgs += & $transform $value } else { $pFmt = "{0}{1}" # quote the strings if they have spaces if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } else { $transform = $param.ArgumentTransform } $__commandArgs += & $transform $value } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message "brew" $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("brew $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "brew")) { throw "Cannot find executable 'brew'" } if ( $__handlerInfo.StreamOutput ) { if ( $null -eq $__handler ) { & "brew" $__commandArgs } else { & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError | & $__handler } } else { $result = & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError & $__handler $result } } # be sure to let the user know if there are any errors Pop-CrescendoNativeError -EmitAsError } # end PROCESS <# .DESCRIPTION Updates an installed package to the latest version .PARAMETER Name Package Name .PARAMETER Formula Formula .PARAMETER Cask Cask #> } function Uninstall-HomebrewPackage { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding()] param( [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Formula')] [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Cask')] [string]$Name, [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Formula')] [switch]$Formula, [Parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName='Cask')] [switch]$Cask ) BEGIN { $PSNativeCommandUseErrorActionPreference = $false $__CrescendoNativeErrorQueue = [System.Collections.Queue]::new() $__PARAMETERMAP = @{ Name = @{ OriginalName = '' OriginalPosition = '0' Position = '2147483647' ParameterType = 'string' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } Formula = @{ OriginalName = '--formula' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } Cask = @{ OriginalName = '--cask' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } } $__outputHandlers = @{ Default = @{ StreamOutput = $False; Handler = { param ( $output ) # Clear the Crescendo stderr queue of Homebrew's abuse of stderr Pop-CrescendoNativeError | Out-Null } } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += 'uninstall' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Where-Object {!$__PARAMETERMAP[$_].ExcludeAsArgument}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { # if a transform is specified, use it and the construction of the values is up to the transform if($param.ArgumentTransform -ne '$args') { $transform = $param.ArgumentTransform if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } $__commandArgs += & $transform $value } else { $pFmt = "{0}{1}" # quote the strings if they have spaces if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } else { $transform = $param.ArgumentTransform } $__commandArgs += & $transform $value } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message "brew" $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("brew $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "brew")) { throw "Cannot find executable 'brew'" } if ( $__handlerInfo.StreamOutput ) { if ( $null -eq $__handler ) { & "brew" $__commandArgs } else { & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError | & $__handler } } else { $result = & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError & $__handler $result } } # be sure to let the user know if there are any errors Pop-CrescendoNativeError -EmitAsError } # end PROCESS <# .DESCRIPTION Uninstall an existing package with Homebrew .PARAMETER Name Package Name .PARAMETER Formula Formula .PARAMETER Cask Cask #> } function Get-HomebrewPackageInfo { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding()] param( [Parameter(ValueFromPipelineByPropertyName=$true)] [string]$Name, [Parameter()] [switch]$Formula, [Parameter()] [switch]$Cask ) BEGIN { $PSNativeCommandUseErrorActionPreference = $false $__CrescendoNativeErrorQueue = [System.Collections.Queue]::new() $__PARAMETERMAP = @{ Name = @{ OriginalName = '' OriginalPosition = '0' Position = '2147483647' ParameterType = 'string' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } Formula = @{ OriginalName = '--formula' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } Cask = @{ OriginalName = '--cask' OriginalPosition = '0' Position = '2147483647' ParameterType = 'switch' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } } $__outputHandlers = @{ Default = @{ StreamOutput = $False; Handler = { param ( $output ) $output | ConvertFrom-Json | ForEach-Object { $_.formulae | Select-Object *, @{Name = 'Formula'; Expression = { $true } } $_.casks | Select-Object *, @{Name = 'Cask'; Expression = { $true } } } } } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += 'info' $__commandArgs += '--json=v2' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Where-Object {!$__PARAMETERMAP[$_].ExcludeAsArgument}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { # if a transform is specified, use it and the construction of the values is up to the transform if($param.ArgumentTransform -ne '$args') { $transform = $param.ArgumentTransform if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } $__commandArgs += & $transform $value } else { $pFmt = "{0}{1}" # quote the strings if they have spaces if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } else { $transform = $param.ArgumentTransform } $__commandArgs += & $transform $value } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message "brew" $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("brew $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "brew")) { throw "Cannot find executable 'brew'" } if ( $__handlerInfo.StreamOutput ) { if ( $null -eq $__handler ) { & "brew" $__commandArgs } else { & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError | & $__handler } } else { $result = & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError & $__handler $result } } # be sure to let the user know if there are any errors Pop-CrescendoNativeError -EmitAsError } # end PROCESS <# .DESCRIPTION Shows information on a specific Homebrew package .PARAMETER Name Package Name .PARAMETER Formula Formula .PARAMETER Cask Cask #> } function Get-HomebrewTapInfo { [PowerShellCustomFunctionAttribute(RequiresElevation=$False)] [CmdletBinding(DefaultParameterSetName='Default')] param( [Parameter(ValueFromPipelineByPropertyName=$true)] [string]$Name ) BEGIN { $PSNativeCommandUseErrorActionPreference = $false $__CrescendoNativeErrorQueue = [System.Collections.Queue]::new() $__PARAMETERMAP = @{ Name = @{ OriginalName = '' OriginalPosition = '0' Position = '2147483647' ParameterType = 'string' ApplyToExecutable = $False NoGap = $False ArgumentTransform = '$args' ArgumentTransformType = 'inline' } } $__outputHandlers = @{ Default = @{ StreamOutput = $False; Handler = { param ( $output ) $output | ConvertFrom-Json } } } } PROCESS { $__boundParameters = $PSBoundParameters $__defaultValueParameters = $PSCmdlet.MyInvocation.MyCommand.Parameters.Values.Where({$_.Attributes.Where({$_.TypeId.Name -eq "PSDefaultValueAttribute"})}).Name $__defaultValueParameters.Where({ !$__boundParameters["$_"] }).ForEach({$__boundParameters["$_"] = get-variable -value $_}) $__commandArgs = @() $MyInvocation.MyCommand.Parameters.Values.Where({$_.SwitchParameter -and $_.Name -notmatch "Debug|Whatif|Confirm|Verbose" -and ! $__boundParameters[$_.Name]}).ForEach({$__boundParameters[$_.Name] = [switch]::new($false)}) if ($__boundParameters["Debug"]){wait-debugger} $__commandArgs += 'tap-info' $__commandArgs += '--json' foreach ($paramName in $__boundParameters.Keys| Where-Object {!$__PARAMETERMAP[$_].ApplyToExecutable}| Where-Object {!$__PARAMETERMAP[$_].ExcludeAsArgument}| Sort-Object {$__PARAMETERMAP[$_].OriginalPosition}) { $value = $__boundParameters[$paramName] $param = $__PARAMETERMAP[$paramName] if ($param) { if ($value -is [switch]) { if ($value.IsPresent) { if ($param.OriginalName) { $__commandArgs += $param.OriginalName } } elseif ($param.DefaultMissingValue) { $__commandArgs += $param.DefaultMissingValue } } elseif ( $param.NoGap ) { # if a transform is specified, use it and the construction of the values is up to the transform if($param.ArgumentTransform -ne '$args') { $transform = $param.ArgumentTransform if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } $__commandArgs += & $transform $value } else { $pFmt = "{0}{1}" # quote the strings if they have spaces if($value -match "\s") { $pFmt = "{0}""{1}""" } $__commandArgs += $pFmt -f $param.OriginalName, $value } } else { if($param.OriginalName) { $__commandArgs += $param.OriginalName } if($param.ArgumentTransformType -eq 'inline') { $transform = [scriptblock]::Create($param.ArgumentTransform) } else { $transform = $param.ArgumentTransform } $__commandArgs += & $transform $value } } } $__commandArgs = $__commandArgs | Where-Object {$_ -ne $null} if ($__boundParameters["Debug"]){wait-debugger} if ( $__boundParameters["Verbose"]) { Write-Verbose -Verbose -Message "brew" $__commandArgs | Write-Verbose -Verbose } $__handlerInfo = $__outputHandlers[$PSCmdlet.ParameterSetName] if (! $__handlerInfo ) { $__handlerInfo = $__outputHandlers["Default"] # Guaranteed to be present } $__handler = $__handlerInfo.Handler if ( $PSCmdlet.ShouldProcess("brew $__commandArgs")) { # check for the application and throw if it cannot be found if ( -not (Get-Command -ErrorAction Ignore "brew")) { throw "Cannot find executable 'brew'" } if ( $__handlerInfo.StreamOutput ) { if ( $null -eq $__handler ) { & "brew" $__commandArgs } else { & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError | & $__handler } } else { $result = & "brew" $__commandArgs 2>&1| Push-CrescendoNativeError & $__handler $result } } # be sure to let the user know if there are any errors Pop-CrescendoNativeError -EmitAsError } # end PROCESS <# .DESCRIPTION Shows information on a specific Homebrew package .PARAMETER Name Package Name #> } |