From 638f4da9c284e75cc15a5f7c3e7794d2ccaee277 Mon Sep 17 00:00:00 2001 From: Kevin Kirkpatrick Date: Wed, 18 Nov 2015 13:09:48 -0500 Subject: [PATCH 1/2] Added 'Advanced Function Cmdlet' snippet Added 'Advanced Function Cmdlet' snippet. Syntax layout is based on Microsoft and Community best practices. --- snippets/language-powershell.cson | 3 +++ 1 file changed, 3 insertions(+) diff --git a/snippets/language-powershell.cson b/snippets/language-powershell.cson index 934fc2b..f899cb1 100644 --- a/snippets/language-powershell.cson +++ b/snippets/language-powershell.cson @@ -26,6 +26,9 @@ 'Function Cmdlet': 'prefix': 'func' 'body': '<#\n.SYNOPSIS\n\tShort description\n\n.DESCRIPTION\n\tLong description\n\n.OUTPUTS\n\tThe value returned by this cmdlet\n\n.EXAMPLE\n\tExample of how to use this cmdlet\n\n.LINK\n\tTo other relevant cmdlets or help\n#>\nFunction ${1:Verb}-${2:Noun}\n{\n\t[CmdletBinding()]\n\t[OutputType([Nullable])]\n\tParam\n\t(\n\t\t# Param1 help description\n\t\t[Parameter(Mandatory, ValueFromPipelineByPropertyName, Position=0)]\n\t\t\$Param1,\n\n\t\t# Param2 help description\n\t\t[int]\n\t\t\$Param2\n\t)\n\tBegin\n\t{\n\t\t${3:# code}\n\t}\n\tProcess\n\t{\n\t}\n\tEnd\n\t{\n\t}\n}' + 'Advanced Function Cmdlet': + 'prefix': 'advfunc' + 'body': 'Function ${1:Verb}-${2:Noun} {\n\n<#\n.SYNOPSIS\n\tA brief description of the function or script.\n\n.DESCRIPTION\n\tA detaild description of the function or script.\n\n.PARAMETER Param1\n\tThe description of a parameter. Add a .PARAMETER keyword for each parameter in the function or script syntax.\n\n.PARAMETER Param2\n\tThe description of a parameter.\n\n.INPUTS\n\tThe object input type/s accepted by this cmdlet\n\t(EX: [System.String],[System.Int32])\n\n.OUTPUTS\n\tThe object output type returned by this cmdlet\n\n.EXAMPLE\n\tExample of how to use this cmdlet\n\n.NOTES\n\tAdditional information about the function or script.\n\n.LINK\n\tabout_functions_advanced\n\n.LINK\n\tabout_comment_based_help\n\n.LINK\n\tabout_functions_advanced_parameters\n#>\n\n\t[CmdletBinding()]\n\tParam\n\t(\n\t\t[Parameter(Position=0, Mandatory=$true)]\n\t\t\[System.String]$Param1,\n\n\t\t[Parameter(Position=1, Mandatory=$false)]\n\t\t[System.Int32]$Param2\n\t)\n\n\tBEGIN {\n\n\t\ttry {\n\n\t\t\t # try executing this code\n\n\t\t} catch {\n\n\t\t\t # catch errors; execute this code\n\n\t\t} # end try/catch\n\n\t} # end BEGIN block\n\n\tPROCESS {\n\n\t\ttry {\n\n\t\t\t # try executing this code\n\n\t\t} catch {\n\n\t\t\t # catch errors; execute this code\n\n\t\t} # end try/catch\n\n\t} # end PROCESS block\n\n\tEND {\n\n\t\ttry {\n\n\t\t\t # try executing this code\n\n\t\t} catch {\n\n\t\t\t # catch errors; execute this code\n\n\t\t} # end try/catch\n\n\t} # end END block\n\n} # end function Verb-Noun' 'Switch': 'prefix': 'switch' 'body': 'switch (\$${1:x})\n{\n\t"value1" {}\n\t{\$_ -in "A","B","C"} {}\n\t"value3" {}\n\tDefault {}\n}' From 32cd7f59c3f79adb726b9abff70c11150ee8538c Mon Sep 17 00:00:00 2001 From: Kevin Kirkpatrick Date: Wed, 18 Nov 2015 13:26:38 -0500 Subject: [PATCH 2/2] Updated function snippets - Updated 'Function Cmdlet' snippet to include some best practice changes and spacing - Updated 'Advanced Cmdlet Cmdlet' to include OutputType --- snippets/language-powershell.cson | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/language-powershell.cson b/snippets/language-powershell.cson index f899cb1..f162945 100644 --- a/snippets/language-powershell.cson +++ b/snippets/language-powershell.cson @@ -25,10 +25,10 @@ 'body': '.SYNOPSIS\n' 'Function Cmdlet': 'prefix': 'func' - 'body': '<#\n.SYNOPSIS\n\tShort description\n\n.DESCRIPTION\n\tLong description\n\n.OUTPUTS\n\tThe value returned by this cmdlet\n\n.EXAMPLE\n\tExample of how to use this cmdlet\n\n.LINK\n\tTo other relevant cmdlets or help\n#>\nFunction ${1:Verb}-${2:Noun}\n{\n\t[CmdletBinding()]\n\t[OutputType([Nullable])]\n\tParam\n\t(\n\t\t# Param1 help description\n\t\t[Parameter(Mandatory, ValueFromPipelineByPropertyName, Position=0)]\n\t\t\$Param1,\n\n\t\t# Param2 help description\n\t\t[int]\n\t\t\$Param2\n\t)\n\tBegin\n\t{\n\t\t${3:# code}\n\t}\n\tProcess\n\t{\n\t}\n\tEnd\n\t{\n\t}\n}' + 'body': 'Function ${1:Verb}-${2:Noun} {\n\n<#\n.SYNOPSIS\n\tA brief description of the function or script.\n\n.DESCRIPTION\n\tA detaild description of the function or script.\n\n.PARAMETER Param1\n\tThe description of a parameter. Add a .PARAMETER keyword for each parameter in the function or script syntax.\n\n.PARAMETER Param2\n\tThe description of a parameter.\n\n.INPUTS\n\tThe object input type/s accepted by this cmdlet\n\t(EX: [System.String],[System.Int32])\n\n.OUTPUTS\n\tThe object output type returned by this cmdlet\n\n.EXAMPLE\n\tExample of how to use this cmdlet\n\n.NOTES\n\tAdditional information about the function or script.\n\n.LINK\n\tabout_functions_advanced\n\n.LINK\n\tabout_comment_based_help\n\n.LINK\n\tabout_functions_advanced_parameters\n#>\n\n\t[CmdletBinding()]\n\t[OutputType([System.Nullable])]\n\tParam\n\t(\n\t\t[Parameter(Position=0, Mandatory=$true)]\n\t\t\[System.String]$Param1,\n\n\t\t[Parameter(Position=1, Mandatory=$false)]\n\t\t[System.Int32]$Param2\n\t)\n\n\tBEGIN {\n\n\t\t # run this code to setup environment\n\n\t} # end BEGIN block\n\n\tPROCESS {\n\n\t\t # production code\n\n\t} # end PROCESS block\n\n\tEND {\n\n\t\t # cleanup code\n\n\t} # end END block\n\n} # end function Verb-Noun' 'Advanced Function Cmdlet': - 'prefix': 'advfunc' - 'body': 'Function ${1:Verb}-${2:Noun} {\n\n<#\n.SYNOPSIS\n\tA brief description of the function or script.\n\n.DESCRIPTION\n\tA detaild description of the function or script.\n\n.PARAMETER Param1\n\tThe description of a parameter. Add a .PARAMETER keyword for each parameter in the function or script syntax.\n\n.PARAMETER Param2\n\tThe description of a parameter.\n\n.INPUTS\n\tThe object input type/s accepted by this cmdlet\n\t(EX: [System.String],[System.Int32])\n\n.OUTPUTS\n\tThe object output type returned by this cmdlet\n\n.EXAMPLE\n\tExample of how to use this cmdlet\n\n.NOTES\n\tAdditional information about the function or script.\n\n.LINK\n\tabout_functions_advanced\n\n.LINK\n\tabout_comment_based_help\n\n.LINK\n\tabout_functions_advanced_parameters\n#>\n\n\t[CmdletBinding()]\n\tParam\n\t(\n\t\t[Parameter(Position=0, Mandatory=$true)]\n\t\t\[System.String]$Param1,\n\n\t\t[Parameter(Position=1, Mandatory=$false)]\n\t\t[System.Int32]$Param2\n\t)\n\n\tBEGIN {\n\n\t\ttry {\n\n\t\t\t # try executing this code\n\n\t\t} catch {\n\n\t\t\t # catch errors; execute this code\n\n\t\t} # end try/catch\n\n\t} # end BEGIN block\n\n\tPROCESS {\n\n\t\ttry {\n\n\t\t\t # try executing this code\n\n\t\t} catch {\n\n\t\t\t # catch errors; execute this code\n\n\t\t} # end try/catch\n\n\t} # end PROCESS block\n\n\tEND {\n\n\t\ttry {\n\n\t\t\t # try executing this code\n\n\t\t} catch {\n\n\t\t\t # catch errors; execute this code\n\n\t\t} # end try/catch\n\n\t} # end END block\n\n} # end function Verb-Noun' + 'prefix': 'funcadv' + 'body': 'Function ${1:Verb}-${2:Noun} {\n\n<#\n.SYNOPSIS\n\tA brief description of the function or script.\n\n.DESCRIPTION\n\tA detaild description of the function or script.\n\n.PARAMETER Param1\n\tThe description of a parameter. Add a .PARAMETER keyword for each parameter in the function or script syntax.\n\n.PARAMETER Param2\n\tThe description of a parameter.\n\n.INPUTS\n\tThe object input type/s accepted by this cmdlet\n\t(EX: [System.String],[System.Int32])\n\n.OUTPUTS\n\tThe object output type returned by this cmdlet\n\n.EXAMPLE\n\tExample of how to use this cmdlet\n\n.NOTES\n\tAdditional information about the function or script.\n\n.LINK\n\tabout_functions_advanced\n\n.LINK\n\tabout_comment_based_help\n\n.LINK\n\tabout_functions_advanced_parameters\n#>\n\n\t[CmdletBinding()]\n\t[OutputType([System.Nullable])]\n\tParam\n\t(\n\t\t[Parameter(Position=0, Mandatory=$true)]\n\t\t\[System.String]$Param1,\n\n\t\t[Parameter(Position=1, Mandatory=$false)]\n\t\t[System.Int32]$Param2\n\t)\n\n\tBEGIN {\n\n\t\ttry {\n\n\t\t\t # try executing this code\n\n\t\t} catch {\n\n\t\t\t # catch errors; execute this code\n\n\t\t} # end try/catch\n\n\t} # end BEGIN block\n\n\tPROCESS {\n\n\t\ttry {\n\n\t\t\t # try executing this code\n\n\t\t} catch {\n\n\t\t\t # catch errors; execute this code\n\n\t\t} # end try/catch\n\n\t} # end PROCESS block\n\n\tEND {\n\n\t\ttry {\n\n\t\t\t # try executing this code\n\n\t\t} catch {\n\n\t\t\t # catch errors; execute this code\n\n\t\t} # end try/catch\n\n\t} # end END block\n\n} # end function Verb-Noun' 'Switch': 'prefix': 'switch' 'body': 'switch (\$${1:x})\n{\n\t"value1" {}\n\t{\$_ -in "A","B","C"} {}\n\t"value3" {}\n\tDefault {}\n}'