Skip to content

Commit 2093b3e

Browse files
Add an extended Snippet for Advanced Functions (#5203)
fixes #5197 Adds the ISE Advanced Function snippet, with some modern updates and adds placeholder support. --------- Co-authored-by: Justin Grote <[email protected]>
1 parent 3c85165 commit 2093b3e

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

snippets/PowerShell.json

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,101 @@
239239
"}"
240240
]
241241
},
242+
"Function-Advanced-Doc-Full-Example-From-ISE": {
243+
"prefix": ["function-advanced-doc-fromISE", "cmdlet-doc-fromISE"],
244+
"description": "Script advanced function definition with full comment-based help and parameter attributes.",
245+
"body": [
246+
"function ${1:Verb-Noun} {",
247+
"\t<#",
248+
"\t.SYNOPSIS",
249+
"\t${2:Short description}",
250+
"\t.DESCRIPTION",
251+
"\t${3:Long description}",
252+
"\t.EXAMPLE",
253+
"\t${4:Example of how to use this cmdlet}",
254+
"\t.EXAMPLE",
255+
"\t${5:Another example of how to use this cmdlet}",
256+
"\t.INPUTS",
257+
"\t${6:Inputs to this cmdlet (if any)}",
258+
"\t.OUTPUTS",
259+
"\t${7:Output from this cmdlet (if any)}",
260+
"\t.NOTES",
261+
"\t${8:General notes}",
262+
"\t.COMPONENT",
263+
"\t${9:The component this cmdlet belongs to}",
264+
"\t.ROLE",
265+
"\t${10:The role this cmdlet belongs to}",
266+
"\t.FUNCTIONALITY",
267+
"\t${11:The functionality that best describes this cmdlet}",
268+
"\t#>",
269+
"\t[CmdletBinding(DefaultParameterSetName = '${12:ParameterSet1}',",
270+
"\t\tSupportsShouldProcess,",
271+
"\t\tPositionalBinding,",
272+
"\t\tHelpUri = '${13:http://yourwebsiteforhelp.here}',",
273+
"\t\tConfirmImpact = 'Medium')]",
274+
"\t[Alias('${14:Be-lazyWithThis}','${15:lzy}','${16:Use-OldFunctionName}')]",
275+
"\t[OutputType([${17:String}])]",
276+
"\tparam (",
277+
"\t\t# ${18:Param1} help description",
278+
"\t\t[Parameter(Mandatory,",
279+
"\t\t\tValueFromPipeline,",
280+
"\t\t\tValueFromPipelineByPropertyName,",
281+
"\t\t\tValueFromRemainingArguments,",
282+
"\t\t\tPosition = 0,",
283+
"\t\t\tParameterSetName = '${12:ParameterSet1}')]",
284+
"\t\t[ValidateNotNull()]",
285+
"\t\t[ValidateNotNullOrEmpty()]",
286+
"\t\t[ValidateCount(0, 5)]",
287+
"\t\t[ValidateSet(\"${19:sun}\", \"${20:moon}\", \"${21:earth}\")]",
288+
"\t\t[Alias(\"${22:p1}\")]",
289+
"\t\t$${18:Param1},",
290+
"",
291+
"\t\t# ${24:Param2} help description",
292+
"\t\t[Parameter(ParameterSetName = '${12:ParameterSet1}')]",
293+
"\t\t[AllowNull()]",
294+
"\t\t[AllowEmptyCollection()]",
295+
"\t\t[AllowEmptyString()]",
296+
"\t\t[ValidateScript({ ${25:true} })]",
297+
"\t\t[ValidateRange(0, 5)]",
298+
"\t\t[${26:int}]",
299+
"\t\t$${24:Param2},",
300+
"",
301+
"\t\t# ${28:Param3} help description",
302+
"\t\t[Parameter(ParameterSetName = '${29:Another Parameter Set}')]",
303+
"\t\t[ValidatePattern(\"${30:[a-z]*}\")]",
304+
"\t\t[ValidateLength(0, 15)]",
305+
"\t\t[${31:String}]",
306+
"\t\t$${28:Param3},",
307+
"",
308+
"\t\t# ${33:Param4} help description",
309+
"\t\t# Checkout the docs https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_argument_completion?view=powershell-7.5#argumentcompletions-attribute on different ways to provide Argument Completion",
310+
"\t\t[Parameter(ParameterSetName = '${34:Yet Another Parameter Set}')]",
311+
"\t\t[ArgumentCompleter({'${35:add completer script}'})]",
312+
"\t\t[ValidateLength(0, 15)]",
313+
"\t\t[${36:String}]",
314+
"\t\t$${33:Param4}",
315+
"\t)",
316+
"",
317+
"\tbegin {",
318+
"\t\t${38:#BeginCodeHere}",
319+
"\t}",
320+
"",
321+
"\tprocess {",
322+
"\t\tif (\\$pscmdlet.ShouldProcess(\"${39:Target}\", \"${40:Operation}\")) {",
323+
"\t\t\t${41:#ProcessCodeHere}",
324+
"\t\t}",
325+
"\t}",
326+
"",
327+
"\tend {",
328+
"\t\t${42:#EndCodeHere}",
329+
"\t}",
330+
"",
331+
"\tclean {",
332+
"\t\t${43:#CleanCodeHere} - Added in 7.3 for more information see https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced_methods?view=powershell-7.5#clean",
333+
"\t}",
334+
"}"
335+
]
336+
},
242337
"Function-Inline": {
243338
"prefix": "function-inline",
244339
"description": "Function definition snippet that does not contain a param block, but defines parameters inline. This syntax is commonly used in other languages. More: Get-Help about_Functions",

0 commit comments

Comments
 (0)