-
Notifications
You must be signed in to change notification settings - Fork 513
Add an extended Snippet for Advanced Functions fixes #5197 #5203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,6 +238,93 @@ | |
"\t}", | ||
"}" | ||
] | ||
}, | ||
"Function-Advanced-Doc": { | ||
"prefix": ["function-advanced-doc", "cmdlet-doc"], | ||
"description": "Script advanced function definition with full comment-based help and parameter attributes.", | ||
"body": [ | ||
"function ${1:Verb-Noun} {", | ||
"\t<#", | ||
"\t.SYNOPSIS", | ||
"\tShort description", | ||
"\t.DESCRIPTION", | ||
"\tLong description", | ||
"\t.EXAMPLE", | ||
"\tExample of how to use this cmdlet", | ||
"\t.EXAMPLE", | ||
"\tAnother example of how to use this cmdlet", | ||
"\t.INPUTS", | ||
"\tInputs to this cmdlet (if any)", | ||
"\t.OUTPUTS", | ||
"\tOutput from this cmdlet (if any)", | ||
"\t.NOTES", | ||
"\tGeneral notes", | ||
"\t.COMPONENT", | ||
"\tThe component this cmdlet belongs to", | ||
"\t.ROLE", | ||
"\tThe role this cmdlet belongs to", | ||
"\t.FUNCTIONALITY", | ||
"\tThe functionality that best describes this cmdlet", | ||
"\t#>", | ||
"\t[CmdletBinding(DefaultParameterSetName = 'Parameter Set 1',", | ||
"\t\tSupportsShouldProcess = \\$true,", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"\t\tPositionalBinding = \\$false,", | ||
"\t\tHelpUri = 'http://www.microsoft.com/',", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure how I feel about this as a placeholder, it implies the cmdlet is microsoft-supported. Maybe something like |
||
"\t\tConfirmImpact = 'Medium')]", | ||
"\t[Alias()]", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No alias is defined, did you want to define it with a placeholder? |
||
"\t[OutputType([String])]", | ||
"\tparam (", | ||
"\t\t# Param1 help description", | ||
"\t\t[Parameter(Mandatory = \\$true,", | ||
"\t\t\tValueFromPipeline = \\$true,", | ||
"\t\t\tValueFromPipelineByPropertyName = \\$true,", | ||
"\t\t\tValueFromRemainingArguments = \\$false,", | ||
"\t\t\tPosition = 0,", | ||
"\t\t\tParameterSetName = 'Parameter Set 1')]", | ||
"\t\t[ValidateNotNull()]", | ||
"\t\t[ValidateNotNullOrEmpty()]", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aren't these two attributes overlapping? Or are you trying to have a snippet that shows all possible options? |
||
"\t\t[ValidateCount(0, 5)]", | ||
"\t\t[ValidateSet(\"sun\", \"moon\", \"earth\")]", | ||
"\t\t[Alias(\"p1\")]", | ||
"\t\t\\$Param1,", | ||
"", | ||
"\t\t# Param2 help description", | ||
"\t\t[Parameter(ParameterSetName = 'Parameter Set 1')]", | ||
"\t\t[AllowNull()]", | ||
"\t\t[AllowEmptyCollection()]", | ||
"\t\t[AllowEmptyString()]", | ||
"\t\t[ValidateScript({ \\$true })]", | ||
"\t\t[ValidateRange(0, 5)]", | ||
"\t\t[int]", | ||
"\t\t\\$Param2,", | ||
"", | ||
"\t\t# Param3 help description", | ||
"\t\t[Parameter(ParameterSetName = 'Another Parameter Set')]", | ||
"\t\t[ValidatePattern(\"[a-z]*\")]", | ||
"\t\t[ValidateLength(0, 15)]", | ||
"\t\t[String]", | ||
"\t\t\\$Param3", | ||
"\t)", | ||
"", | ||
"\tbegin {", | ||
"\t\t#BeginCodeHere", | ||
"\t}", | ||
"", | ||
"\tprocess {", | ||
"\t\tif (\\$pscmdlet.ShouldProcess(\"Target\", \"Operation\")) {", | ||
"\t\t\t#ProcessCodeHere", | ||
"\t\t}", | ||
"\t}", | ||
"", | ||
"\tend {", | ||
"\t\t#EndCodeHere", | ||
"\t}", | ||
"", | ||
"\tclean {", | ||
"\t\t#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", | ||
"\t}", | ||
"}" | ||
] | ||
}, | ||
"Function-Inline": { | ||
"prefix": "function-inline", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a bit of extra work but I feel it's reasonable for all of these placeholders to be formatted as snippet placeholders, that way you can just tab down and fill out the information as you go.