From 97aeddc07f80297c19ed0ca3afb1f259c4a4ab1c Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Tue, 28 Aug 2018 22:02:24 -0700 Subject: [PATCH 1/7] initial commit of module --- ...re.Functions.PowerShell.Worker.Module.psd1 | 122 ++++++++++++++++++ ...re.Functions.PowerShell.Worker.Module.psm1 | 103 +++++++++++++++ 2 files changed, 225 insertions(+) create mode 100644 src/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psd1 create mode 100644 src/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 diff --git a/src/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psd1 b/src/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psd1 new file mode 100644 index 00000000..a7b4bd2a --- /dev/null +++ b/src/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psd1 @@ -0,0 +1,122 @@ +# +# Module manifest for module 'Azure.Functions.PowerShell.Worker.Module' +# +# Generated by: tylerleonhardt +# +# Generated on: 8/28/18 +# + +@{ + +# Script module or binary module file associated with this manifest. +RootModule = 'Azure.Functions.PowerShell.Worker.Module.psm1' + +# Version number of this module. +ModuleVersion = '0.1.0' + +# Supported PSEditions +CompatiblePSEditions = @('Desktop', 'Core') + +# ID used to uniquely identify this module +GUID = 'f0149ba6-bd6f-4dbd-afe5-2a95bd755d6c' + +# Author of this module +Author = 'Microsoft Corporation' + +# Company or vendor of this module +CompanyName = 'Microsoft Corporation' + +# Copyright statement for this module +Copyright = '(c) Microsoft Corporation. All rights reserved.' + +# Description of the functionality provided by this module +# Description = '' + +# Minimum version of the PowerShell engine required by this module +# PowerShellVersion = '' + +# Name of the PowerShell host required by this module +# PowerShellHostName = '' + +# Minimum version of the PowerShell host required by this module +# PowerShellHostVersion = '' + +# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# DotNetFrameworkVersion = '' + +# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. +# CLRVersion = '' + +# Processor architecture (None, X86, Amd64) required by this module +# ProcessorArchitecture = '' + +# Modules that must be imported into the global environment prior to importing this module +# RequiredModules = @() + +# Assemblies that must be loaded prior to importing this module +# RequiredAssemblies = @() + +# Script files (.ps1) that are run in the caller's environment prior to importing this module. +# ScriptsToProcess = @() + +# Type files (.ps1xml) to be loaded when importing this module +# TypesToProcess = @() + +# Format files (.ps1xml) to be loaded when importing this module +# FormatsToProcess = @() + +# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess +# NestedModules = @() + +# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. +FunctionsToExport = @('Push-OutputBinding', 'Get-OutputBinding') + +# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. +CmdletsToExport = @() + +# Variables to export from this module +VariablesToExport = '*' + +# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. +AliasesToExport = @() + +# DSC resources to export from this module +# DscResourcesToExport = @() + +# List of all modules packaged with this module +# ModuleList = @() + +# List of all files packaged with this module +# FileList = @() + +# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. +PrivateData = @{ + + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + # Tags = @() + + # A URL to the license for this module. + # LicenseUri = '' + + # A URL to the main website for this project. + # ProjectUri = '' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + # ReleaseNotes = '' + + } # End of PSData hashtable + +} # End of PrivateData hashtable + +# HelpInfo URI of this module +# HelpInfoURI = '' + +# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. +# DefaultCommandPrefix = '' + +} \ No newline at end of file diff --git a/src/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 b/src/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 new file mode 100644 index 00000000..434c18e0 --- /dev/null +++ b/src/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 @@ -0,0 +1,103 @@ +# +# Copyright (c) Microsoft. All rights reserved. +# Licensed under the MIT license. See LICENSE file in the project root for full license information. +# + +# This holds the current state of the output bindings +$script:_OutputBindings = @{} + +<# +.SYNOPSIS + Sets the value for the specified output binding. +.DESCRIPTION + Sets the value for the specified output binding. +.EXAMPLE + PS > Push-OutputBinding -Name res -Value "my output" + The output binding of "res" will have the value of "my output" +.PARAMETER Name + The name of the output binding you want to set. +.PARAMETER Value + The value of the output binding you want to set. +.PARAMETER InputObject + The hashtable that contains the output binding names to their respective value. +.PARAMETER Force + (Optional) If specified, will force the value to be set for a specified output binding. +#> +function Push-OutputBinding { + [CmdletBinding()] + param ( + [Parameter( + Mandatory=$true, + ParameterSetName="NameValue")] + [string] + $Name, + + [Parameter( + Mandatory=$true, + ParameterSetName="NameValue")] + $Value, + + [Parameter( + Mandatory=$true, + ValueFromPipeline=$true, + ParameterSetName="InputObject")] + $InputObject, + + [switch] + $Force + ) + $dict = @{} + switch ($PSCmdlet.ParameterSetName) { + NameValue { + $dict[$Name] = $Value + } + InputObject { + $dict = $InputObject + } + } + + $dict.GetEnumerator() | ForEach-Object { + if(!$script:_OutputBindings.ContainsKey($_.Name) -or $Force.IsPresent) { + $script:_OutputBindings[$_.Name] = $_.Value + } else { + throw "Output binding '$($_.Name)' is already set. To override the value, use -Force." + } + } +} + +<# +.SYNOPSIS + Gets the hashtable of the output bindings set so far. +.DESCRIPTION + Gets the hashtable of the output bindings set so far. +.EXAMPLE + PS > Get-OutputBinding + Gets the hashtable of all the output bindings set so far. +.EXAMPLE + PS > Get-OutputBinding -Name res + Gets the hashtable of specific output binding. +.EXAMPLE + PS > Get-OutputBinding -Name r* + Gets the hashtable of output bindings that match the wildcard. +.PARAMETER Name + The name of the output binding you want to get. Supports wildcards. +.OUTPUTS + The hashtable of binding names to their respective value. +#> +function Get-OutputBinding { + [CmdletBinding()] + param( + [Parameter(ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)] + [string[]] + $Name = '*' + ) + begin { + $bindings = @{} + } + process { + $script:_OutputBindings.GetEnumerator() | Where-Object Name -Like $Name | ForEach-Object { $null = $bindings.Add($_.Name, $_.Value) } + } + end { + return $bindings + } +} \ No newline at end of file From c3d15a02515a49ca592ae7e0bd8f7cbf408642fb Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Wed, 29 Aug 2018 11:59:25 -0700 Subject: [PATCH 2/7] address feedback and move module into worker --- ...re.Functions.PowerShell.Worker.Module.psd1 | 10 +---- ...re.Functions.PowerShell.Worker.Module.psm1 | 45 +++++++++++-------- .../Azure.Functions.PowerShell.Worker.csproj | 3 ++ 3 files changed, 31 insertions(+), 27 deletions(-) rename src/{ => Azure.Functions.PowerShell.Worker}/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psd1 (96%) rename src/{ => Azure.Functions.PowerShell.Worker}/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 (70%) diff --git a/src/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psd1 b/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psd1 similarity index 96% rename from src/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psd1 rename to src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psd1 index a7b4bd2a..fcfd4608 100644 --- a/src/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psd1 +++ b/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psd1 @@ -1,11 +1,3 @@ -# -# Module manifest for module 'Azure.Functions.PowerShell.Worker.Module' -# -# Generated by: tylerleonhardt -# -# Generated on: 8/28/18 -# - @{ # Script module or binary module file associated with this manifest. @@ -119,4 +111,4 @@ PrivateData = @{ # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. # DefaultCommandPrefix = '' -} \ No newline at end of file +} diff --git a/src/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 b/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 similarity index 70% rename from src/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 rename to src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 index 434c18e0..0fd5c0df 100644 --- a/src/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 +++ b/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 @@ -28,39 +28,48 @@ function Push-OutputBinding { param ( [Parameter( Mandatory=$true, - ParameterSetName="NameValue")] + ParameterSetName="NameValue", + Position=0, + ValueFromPipelineByPropertyName=$true)] [string] $Name, [Parameter( Mandatory=$true, - ParameterSetName="NameValue")] + ParameterSetName="NameValue", + Position=1, + ValueFromPipelineByPropertyName=$true)] + [object] $Value, [Parameter( Mandatory=$true, - ValueFromPipeline=$true, - ParameterSetName="InputObject")] + ParameterSetName="InputObject", + Position=0, + ValueFromPipeline=$true)] + [hashtable] $InputObject, [switch] $Force ) - $dict = @{} - switch ($PSCmdlet.ParameterSetName) { - NameValue { - $dict[$Name] = $Value - } - InputObject { - $dict = $InputObject + process { + $dict = @{} + switch ($PSCmdlet.ParameterSetName) { + NameValue { + $dict[$Name] = $Value + } + InputObject { + $dict = $InputObject + } } - } - $dict.GetEnumerator() | ForEach-Object { - if(!$script:_OutputBindings.ContainsKey($_.Name) -or $Force.IsPresent) { - $script:_OutputBindings[$_.Name] = $_.Value - } else { - throw "Output binding '$($_.Name)' is already set. To override the value, use -Force." + $dict.GetEnumerator() | ForEach-Object { + if(!$script:_OutputBindings.ContainsKey($_.Name) -or $Force.IsPresent) { + $script:_OutputBindings[$_.Name] = $_.Value + } else { + throw "Output binding '$($_.Name)' is already set. To override the value, use -Force." + } } } } @@ -100,4 +109,4 @@ function Get-OutputBinding { end { return $bindings } -} \ No newline at end of file +} diff --git a/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.csproj b/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.csproj index bfe63885..b61b9498 100644 --- a/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.csproj +++ b/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.csproj @@ -19,6 +19,9 @@ PreserveNewest + + PreserveNewest + From 1476d6267e5ff93243f74565267bf282e0111fd5 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Wed, 29 Aug 2018 13:46:47 -0700 Subject: [PATCH 3/7] address Dongbo's feedback --- ...re.Functions.PowerShell.Worker.Module.psm1 | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 b/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 index 0fd5c0df..13db163a 100644 --- a/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 +++ b/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 @@ -54,21 +54,22 @@ function Push-OutputBinding { $Force ) process { - $dict = @{} switch ($PSCmdlet.ParameterSetName) { NameValue { - $dict[$Name] = $Value + if(!$script:_OutputBindings.ContainsKey($Name) -or $Force.IsPresent) { + $script:_OutputBindings[$Name] = $Value + } else { + throw "Output binding '$Name' is already set. To override the value, use -Force." + } } InputObject { - $dict = $InputObject - } - } - - $dict.GetEnumerator() | ForEach-Object { - if(!$script:_OutputBindings.ContainsKey($_.Name) -or $Force.IsPresent) { - $script:_OutputBindings[$_.Name] = $_.Value - } else { - throw "Output binding '$($_.Name)' is already set. To override the value, use -Force." + $InputObject.GetEnumerator() | ForEach-Object { + if(!$script:_OutputBindings.ContainsKey($_.Name) -or $Force.IsPresent) { + $script:_OutputBindings[$_.Name] = $_.Value + } else { + throw "Output binding '$($_.Name)' is already set. To override the value, use -Force." + } + } } } } From 128fdc1e2bd1852f25a9e69c8dfaee29e7496120 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Wed, 29 Aug 2018 15:35:14 -0700 Subject: [PATCH 4/7] remove psd1 fields and change Set logic --- ...re.Functions.PowerShell.Worker.Module.psd1 | 62 +++++-------------- ...re.Functions.PowerShell.Worker.Module.psm1 | 21 ++++--- 2 files changed, 27 insertions(+), 56 deletions(-) diff --git a/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psd1 b/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psd1 index fcfd4608..e362844d 100644 --- a/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psd1 +++ b/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psd1 @@ -22,43 +22,28 @@ CompanyName = 'Microsoft Corporation' Copyright = '(c) Microsoft Corporation. All rights reserved.' # Description of the functionality provided by this module -# Description = '' +Description = 'The module used in an Azure Functions environment for setting and retrieving Output Bindings.' # Minimum version of the PowerShell engine required by this module -# PowerShellVersion = '' - -# Name of the PowerShell host required by this module -# PowerShellHostName = '' - -# Minimum version of the PowerShell host required by this module -# PowerShellHostVersion = '' - -# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. -# DotNetFrameworkVersion = '' - -# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. -# CLRVersion = '' - -# Processor architecture (None, X86, Amd64) required by this module -# ProcessorArchitecture = '' +PowerShellVersion = '5.1' # Modules that must be imported into the global environment prior to importing this module -# RequiredModules = @() +RequiredModules = @() # Assemblies that must be loaded prior to importing this module -# RequiredAssemblies = @() +RequiredAssemblies = @() # Script files (.ps1) that are run in the caller's environment prior to importing this module. -# ScriptsToProcess = @() +ScriptsToProcess = @() # Type files (.ps1xml) to be loaded when importing this module -# TypesToProcess = @() +TypesToProcess = @() # Format files (.ps1xml) to be loaded when importing this module -# FormatsToProcess = @() +FormatsToProcess = @() # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess -# NestedModules = @() +NestedModules = @() # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. FunctionsToExport = @('Push-OutputBinding', 'Get-OutputBinding') @@ -72,43 +57,28 @@ VariablesToExport = '*' # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. AliasesToExport = @() -# DSC resources to export from this module -# DscResourcesToExport = @() - -# List of all modules packaged with this module -# ModuleList = @() - -# List of all files packaged with this module -# FileList = @() - # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. PrivateData = @{ PSData = @{ # Tags applied to this module. These help with module discovery in online galleries. - # Tags = @() + Tags = @('Microsoft', 'Azure', 'Functions', 'Serverless', 'Cloud') # A URL to the license for this module. - # LicenseUri = '' + LicenseUri = 'https://github.com/Azure/azure-functions-powershell-worker/blob/dev/LICENSE' # A URL to the main website for this project. - # ProjectUri = '' + ProjectUri = 'https://github.com/Azure/azure-functions-powershell-worker' # A URL to an icon representing this module. # IconUri = '' # ReleaseNotes of this module - # ReleaseNotes = '' - - } # End of PSData hashtable - -} # End of PrivateData hashtable - -# HelpInfo URI of this module -# HelpInfoURI = '' - -# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. -# DefaultCommandPrefix = '' + ReleaseNotes = '# 0.1.0 +Initial Release. +' + } +} } diff --git a/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 b/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 index 13db163a..4a1399cc 100644 --- a/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 +++ b/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 @@ -56,25 +56,26 @@ function Push-OutputBinding { process { switch ($PSCmdlet.ParameterSetName) { NameValue { - if(!$script:_OutputBindings.ContainsKey($Name) -or $Force.IsPresent) { - $script:_OutputBindings[$Name] = $Value - } else { - throw "Output binding '$Name' is already set. To override the value, use -Force." - } + Push-KeyValueOutputBinding -Name $Name -Value $Value -Force:$Force.IsPresent } InputObject { $InputObject.GetEnumerator() | ForEach-Object { - if(!$script:_OutputBindings.ContainsKey($_.Name) -or $Force.IsPresent) { - $script:_OutputBindings[$_.Name] = $_.Value - } else { - throw "Output binding '$($_.Name)' is already set. To override the value, use -Force." - } + Push-KeyValueOutputBinding -Name $_.Name -Value $_.Value -Force:$Force.IsPresent } } } } } +# Helper private function that sets an OutputBinding. +function Push-KeyValueOutputBinding($Name, $Value) { + if(!$script:_OutputBindings.ContainsKey($Name) -or $Force.IsPresent) { + $script:_OutputBindings[$Name] = $Value + } else { + throw "Output binding '$Name' is already set. To override the value, use -Force." + } +} + <# .SYNOPSIS Gets the hashtable of the output bindings set so far. From e8cdd811d80537bf42c7dd49b844af9f8710bded Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Wed, 29 Aug 2018 15:37:00 -0700 Subject: [PATCH 5/7] don't expose vars in psd1 --- .../Azure.Functions.PowerShell.Worker.Module.psd1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psd1 b/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psd1 index e362844d..150be33a 100644 --- a/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psd1 +++ b/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psd1 @@ -52,7 +52,7 @@ FunctionsToExport = @('Push-OutputBinding', 'Get-OutputBinding') CmdletsToExport = @() # Variables to export from this module -VariablesToExport = '*' +VariablesToExport = @() # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. AliasesToExport = @() From ae595fbf2e3aa9b7e9e21668ceb7d5b4ececb5b6 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Wed, 29 Aug 2018 15:43:35 -0700 Subject: [PATCH 6/7] alpha sort functions --- ...re.Functions.PowerShell.Worker.Module.psm1 | 92 +++++++++---------- 1 file changed, 46 insertions(+), 46 deletions(-) diff --git a/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 b/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 index 4a1399cc..2947dfdf 100644 --- a/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 +++ b/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 @@ -6,6 +6,52 @@ # This holds the current state of the output bindings $script:_OutputBindings = @{} +<# +.SYNOPSIS + Gets the hashtable of the output bindings set so far. +.DESCRIPTION + Gets the hashtable of the output bindings set so far. +.EXAMPLE + PS > Get-OutputBinding + Gets the hashtable of all the output bindings set so far. +.EXAMPLE + PS > Get-OutputBinding -Name res + Gets the hashtable of specific output binding. +.EXAMPLE + PS > Get-OutputBinding -Name r* + Gets the hashtable of output bindings that match the wildcard. +.PARAMETER Name + The name of the output binding you want to get. Supports wildcards. +.OUTPUTS + The hashtable of binding names to their respective value. +#> +function Get-OutputBinding { + [CmdletBinding()] + param( + [Parameter(ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)] + [string[]] + $Name = '*' + ) + begin { + $bindings = @{} + } + process { + $script:_OutputBindings.GetEnumerator() | Where-Object Name -Like $Name | ForEach-Object { $null = $bindings.Add($_.Name, $_.Value) } + } + end { + return $bindings + } +} + +# Helper private function that sets an OutputBinding. +function Push-KeyValueOutputBinding($Name, $Value) { + if(!$script:_OutputBindings.ContainsKey($Name) -or $Force.IsPresent) { + $script:_OutputBindings[$Name] = $Value + } else { + throw "Output binding '$Name' is already set. To override the value, use -Force." + } +} + <# .SYNOPSIS Sets the value for the specified output binding. @@ -66,49 +112,3 @@ function Push-OutputBinding { } } } - -# Helper private function that sets an OutputBinding. -function Push-KeyValueOutputBinding($Name, $Value) { - if(!$script:_OutputBindings.ContainsKey($Name) -or $Force.IsPresent) { - $script:_OutputBindings[$Name] = $Value - } else { - throw "Output binding '$Name' is already set. To override the value, use -Force." - } -} - -<# -.SYNOPSIS - Gets the hashtable of the output bindings set so far. -.DESCRIPTION - Gets the hashtable of the output bindings set so far. -.EXAMPLE - PS > Get-OutputBinding - Gets the hashtable of all the output bindings set so far. -.EXAMPLE - PS > Get-OutputBinding -Name res - Gets the hashtable of specific output binding. -.EXAMPLE - PS > Get-OutputBinding -Name r* - Gets the hashtable of output bindings that match the wildcard. -.PARAMETER Name - The name of the output binding you want to get. Supports wildcards. -.OUTPUTS - The hashtable of binding names to their respective value. -#> -function Get-OutputBinding { - [CmdletBinding()] - param( - [Parameter(ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)] - [string[]] - $Name = '*' - ) - begin { - $bindings = @{} - } - process { - $script:_OutputBindings.GetEnumerator() | Where-Object Name -Like $Name | ForEach-Object { $null = $bindings.Add($_.Name, $_.Value) } - } - end { - return $bindings - } -} From e921ec22c6883e89ce0b69cb7c76fe1d642d2648 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Wed, 29 Aug 2018 15:53:43 -0700 Subject: [PATCH 7/7] helper function refactoring --- .../Azure.Functions.PowerShell.Worker.Module.psm1 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 b/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 index 2947dfdf..31e5d3bb 100644 --- a/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 +++ b/src/Azure.Functions.PowerShell.Worker/Azure.Functions.PowerShell.Worker.Module/Azure.Functions.PowerShell.Worker.Module.psm1 @@ -44,7 +44,19 @@ function Get-OutputBinding { } # Helper private function that sets an OutputBinding. -function Push-KeyValueOutputBinding($Name, $Value) { +function Push-KeyValueOutputBinding { + param ( + [Parameter(Mandatory=$true)] + [string] + $Name, + + [Parameter(Mandatory=$true)] + [object] + $Value, + + [switch] + $Force + ) if(!$script:_OutputBindings.ContainsKey($Name) -or $Force.IsPresent) { $script:_OutputBindings[$Name] = $Value } else {