Skip to content

Commit f24d9d6

Browse files
StartAutomatingStartAutomating
authored andcommitted
New-PipeScript: Ensuring [ScriptBlock] inputs only contain parameters (use case of #125)
1 parent 9c55896 commit f24d9d6

File tree

1 file changed

+15
-31
lines changed

1 file changed

+15
-31
lines changed

Get-PipeScript.ps1

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region Piecemeal [ 0.3.2 ] : Easy Extensible Plugins for PowerShell
1+
#region Piecemeal [ 0.3.3 ] : Easy Extensible Plugins for PowerShell
22
# Install-Module Piecemeal -Scope CurrentUser
33
# Import-Module Piecemeal -Force
44
# Install-Piecemeal -ExtensionNoun 'PipeScript' -ExtensionPattern '\.psx\.ps1{0,1}$','\.ps1{0,1}\.(?<ext>[^.]+$)','\.ps1{0,1}$' -ExtensionTypeName 'PipeScript' -OutputPath '.\Get-PipeScript.ps1'
@@ -153,20 +153,7 @@ function Get-PipeScript
153153

154154
# If set, will output the help for the extensions
155155
[switch]
156-
$Help,
157-
158-
# If set, will get help about one or more parameters of an extension
159-
[string[]]
160-
$ParameterHelp,
161-
162-
# If set, will get help examples
163-
[Alias('Examples')]
164-
[switch]
165-
$Example,
166-
167-
# If set, will output the full help for the extensions
168-
[switch]
169-
$FullHelp
156+
$Help
170157
)
171158

172159
begin {
@@ -292,15 +279,21 @@ function Get-PipeScript
292279

293280
$extCmd.PSObject.Methods.Add([psscriptmethod]::New('GetHelpField', {
294281
param([Parameter(Mandatory)]$Field)
295-
foreach ($block in $this.BlockComments) {
282+
$fieldNames = 'synopsis','description','link','example','inputs', 'outputs', 'parameter', 'notes'
283+
foreach ($block in $this.BlockComments) {
296284
foreach ($match in [Regex]::new("
297285
\.(?<Field>$Field) # Field Start
298286
[\s-[\r\n]]{0,} # Optional Whitespace
299287
[\r\n]+ # newline
300-
(?<Content>(.|\s)+?(?=(\.\w+|\#\>))) # Anything until the next .\field or end of the comment block
288+
(?<Content>(?:.|\s)+?(?=
289+
(
290+
[\r\n]{0,}\s{0,}\.(?>$($fieldNames -join '|'))|
291+
\#\>|
292+
\z
293+
))) # Anything until the next .field or end of the comment block
301294
", 'IgnoreCase,IgnorePatternWhitespace', [Timespan]::FromSeconds(1)).Matches(
302295
$block.Value
303-
)) {
296+
)) {
304297
$match.Groups["Content"].Value -replace '[\s\r\n]+$'
305298
}
306299
}
@@ -813,18 +806,9 @@ function Get-PipeScript
813806
}
814807
return
815808
}
816-
elseif ($IsValid -and ($Help -or $FullHelp -or $Example -or $ParameterHelp)) {
817-
$getHelpSplat = @{}
818-
if ($FullHelp) {
819-
$getHelpSplat["Full"] = $true
820-
}
821-
if ($Example) {
822-
$getHelpSplat["Example"] = $true
823-
}
824-
if ($ParameterHelp) {
825-
$getHelpSplat["ParameterHelp"] = $ParameterHelp
826-
}
827-
809+
elseif ($IsValid -and $Help) {
810+
$getHelpSplat = @{Full=$true}
811+
828812
if ($extCmd -is [Management.Automation.ExternalScriptInfo]) {
829813
Get-Help $extCmd.Source @getHelpSplat
830814
} elseif ($extCmd -is [Management.Automation.FunctionInfo]) {
@@ -933,5 +917,5 @@ function Get-PipeScript
933917
}
934918
}
935919
}
936-
#endregion Piecemeal [ 0.3.2 ] : Easy Extensible Plugins for PowerShell
920+
#endregion Piecemeal [ 0.3.3 ] : Easy Extensible Plugins for PowerShell
937921

0 commit comments

Comments
 (0)