Skip to content

Commit b13319d

Browse files
Merge pull request #129 from StartAutomating/PipeScriptFixesAndSyntax
Pipe script fixes and syntax
2 parents cfad468 + 82cae8c commit b13319d

18 files changed

+614
-200
lines changed

.github/workflows/TestAndPublish.yml

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -485,39 +485,18 @@ jobs:
485485
}
486486
}
487487
} @Parameters
488-
UsePiecemeal:
489-
runs-on: ubuntu-latest
490-
if: ${{ success() }}
491-
steps:
492-
- name: Check out repository
493-
uses: actions/checkout@v2
494-
- name: UsePiecemeal
495-
uses: StartAutomating/Piecemeal@main
496-
BuildPipeScript:
488+
BuildModule:
497489
runs-on: ubuntu-latest
498490
if: ${{ success() }}
499491
steps:
500492
- name: Check out repository
501493
uses: actions/checkout@v2
502494
- name: BuildPipeScript
503495
uses: StartAutomating/PipeScript@main
504-
RunEZOut:
505-
runs-on: ubuntu-latest
506-
if: ${{ success() }}
507-
steps:
508-
- name: Check out repository
509-
uses: actions/checkout@v2
510496
- name: UseEZOut
511497
uses: StartAutomating/EZOut@master
512-
- name: Push Changes
513-
shell: pwsh
514-
run: git push; exit 0
515-
HelpOut:
516-
runs-on: ubuntu-latest
517-
if: ${{ success() }}
518-
steps:
519-
- name: Check out repository
520-
uses: actions/checkout@v2
498+
- name: UsePiecemeal
499+
uses: StartAutomating/Piecemeal@main
521500
- name: UseHelpOut
522501
uses: StartAutomating/HelpOut@master
523502
env:

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
## 0.0.9:
2+
* New Features:
3+
* new keyword (#128)
4+
* == operator (#123 (thanks @dfinke))
5+
* Fixes
6+
* REST Transpiler automatically coerces [DateTime] and [switch] parameters (#118)
7+
* Join-PipeScript: Fixing multiparam error (#124)
8+
* ValidateScriptBlock: Only validing ScriptBlocks (#125)
9+
---
10+
111
## 0.0.8:
212
* New Commands:
313
* New-PipeScript (#94)

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

Get-Transpiler.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 'Transpiler' -ExtensionPattern '\.psx\.ps1$' -ExtensionTypeName 'PipeScript.Transpiler' -OutputPath '.\Get-Transpiler.ps1'
@@ -153,20 +153,7 @@ function Get-Transpiler
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-Transpiler
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-Transpiler
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-Transpiler
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

Join-PipeScript.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,12 @@ function Join-PipeScript
143143
$lastParameter = $parameter.Parent.Parameters[$parameterIndex - 1]
144144
$relativeOffset = $lastParameter.Extent.EndOffset + 1 - $parameter.Parent.Extent.StartOffset
145145
$distance = $parameter.Extent.StartOffset - $lastParameter.Extent.EndOffset - 1
146-
$parameter.Parent.Extent.ToString().Substring($relativeOffset, $distance) -replace '^[\r\n]+'
146+
$parameter.Parent.Extent.ToString().Substring($relativeOffset, $distance) -replace '^[\,\s\r\n]+'
147147
} else {
148148
$parentExtent = $parameter.Parent.Extent.ToString()
149149
$afterFirstParens = $parentExtent.IndexOf('(') + 1
150150
$parentExtent.Substring($afterFirstParens,
151-
$parameter.Extent.StartOffset - $parameter.Parent.Extent.StartOffset - $afterFirstParens) -replace '^[\r\n]+'
151+
$parameter.Extent.StartOffset - $parameter.Parent.Extent.StartOffset - $afterFirstParens) -replace '^[\s\r\n]+'
152152
}
153153

154154

@@ -170,7 +170,7 @@ function Join-PipeScript
170170
$parameterIndex++
171171
}
172172
})
173-
$paramOut -join (',' + ([Environment]::NewLine * 2))
173+
$paramOut -notmatch '^[\s\r\n]$' -join (',' + ([Environment]::NewLine * 2))
174174
if (@($AllScriptBlocks.Ast.ParamBlock) -ne $null) {
175175
' ' * (@(@($AllScriptBlocks.Ast.ParamBlock) -ne $null)[0] | MeasureIndent) + ")"
176176
}

0 commit comments

Comments
 (0)