Skip to content

Pipe script updates #117

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

Merged
merged 93 commits into from
Jul 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
5922cd7
Get-Transpiler: Anchoring match (#109)
Jul 6, 2022
c98b58a
Get-Transpiler: Anchoring match (#109)
Jul 6, 2022
13278e2
Fixing Include Pattern (#96)
Jul 6, 2022
6ac7d57
Fixing Include Pattern (#96)
Jul 6, 2022
db9ffc5
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
a431589
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
11b01d8
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
a4023e1
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
b76513c
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
249ac6f
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
703ffee
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
6128051
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
075c34c
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
ef77dda
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
9ea621e
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
3e3ab0b
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
32853e5
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
147ba81
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
fc27ce5
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
5530686
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
56a7d23
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
d64f3a5
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
699a5ad
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
0e4c635
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
3d1231b
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
0f06524
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
72a581a
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
c001907
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
7437621
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
695a96b
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
5630166
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
30ca2ef
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
49a6763
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
5fef1db
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
687373a
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
6bffa25
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
579bdf2
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
5225c9e
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
6ec362c
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
dbaad58
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
2e383a6
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
9e941e7
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
6b8ae9d
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
f92ed4d
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
93e8032
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
7f019fa
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
7ce5668
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
6ea27c0
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
d3e5381
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
9ee01e2
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
35c834a
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
839824f
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
98bccd7
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
5a0d531
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
a94eddf
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
aaa6ceb
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
07797f6
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
02eb83f
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
d136ba6
Updating PipeScript.HelpOut.ps1 (#56)
Jul 6, 2022
4059685
Fixing merge conflict
Jul 9, 2022
94c275b
Adding Inline Kotlin Transpiler (#110)
Jul 9, 2022
b0afce6
Adding Inline Kotlin Transpiler (#110)
Jul 9, 2022
64f1369
Adding Inline Kotlin Transpiler (#110)
Jul 9, 2022
bfb2938
Cleaning up Core Inline Transpiler (#111)
Jul 9, 2022
daf4890
Cleaning up Core Inline Transpiler (#111)
Jul 9, 2022
35c6209
Cleaning up Core Inline Transpiler (#111)
Jul 9, 2022
ec0f50a
Cleaning up Core Inline Transpiler (#111)
Jul 9, 2022
693c3b2
Cleaning up Core Inline Transpiler (#111)
Jul 9, 2022
a2c7af1
Cleaning up Core Inline Transpiler (#111)
Jul 9, 2022
0cc2667
Updating core inline transpiler (sharing context) (#112)
Jul 9, 2022
1509ec2
Updating core inline transpiler (adding parameter help)
Jul 9, 2022
2633715
Updating core inline transpiler (adding parameter help)
Jul 9, 2022
e92d7b1
Adding New-PipeScript (source) (#94)
Jul 9, 2022
d44473f
Adding New-PipeScript (source) (#94)
Jul 9, 2022
26b10e0
Adding REST transpiler (#114)
Jul 9, 2022
c9f19e1
Adding REST transpiler (#114)
Jul 9, 2022
7fa2a7c
Adding REST transpiler (#114)
Jul 9, 2022
475f283
Adding Search-PipeScript (#114)
Jul 10, 2022
8eb40c9
Adding Search-PipeScript (#114)
Jul 10, 2022
e5e1d35
Adding formatting for Search-PipeScript (#115)
Jul 10, 2022
a054ec9
Updating Formatting and Types
Jul 10, 2022
44d149f
Fixing formatting for Search-PipeScript (#115)
Jul 10, 2022
5226ce3
Fixing formatting for Search-PipeScript (#115)
Jul 10, 2022
c5d33f1
Updating Formatting and Types
Jul 10, 2022
23abcb0
Updating Search-PipeScript (fixing match condition) (#115)
Jul 10, 2022
b9ab293
Updating Search-PipeScript (fixing match condition) (#115)
Jul 10, 2022
13917d4
Updating Search-PipeScript (adding -Recurse) (#115)
Jul 10, 2022
cee342a
Updating Search-PipeScript (adding -Recurse) (#115)
Jul 10, 2022
6d550d5
Updating Rest Transpiler (adding -UriParameterHelp and -UriParameterT…
Jul 10, 2022
a341836
Join-PipeScript: Fixing .Substring errors (#116)
Jul 10, 2022
4571669
Join-PipeScript: Fixing .Substring errors (#116)
Jul 10, 2022
e4ae62e
Join-PipeScript: Fixing .Substring errors (#116)
Jul 10, 2022
71e162c
Updating Module Version [0.0.8] and CHANGELOG
Jul 10, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## 0.0.8:
* New Commands:
* New-PipeScript (#94)
* Search-PipeScript (#115)
* New Transpilers:
* REST (#114)
* Inline.Kotlin (#110)
* Bugfixes and improvements:
* Fixing Help Generation (#56)
* Anchoring match for Get-Transpiler (#109)
* Core Inline Transpiler Cleanup (#111)
* Shared Context within Inline Transpilers (#112)
* Fixing Include Transpiler Pattern (#96)
* Join-PipeScript interactive .Substring error (#116)
---

## 0.0.7:
* Syntax Improvements:
* Support for Dot Notation (#107)
Expand Down
1 change: 1 addition & 0 deletions Formatting/Search.PipeScript.Result.format.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Write-FormatView -TypeName Search.PipeScript.Result -GroupByProperty InputObject -Property Result, Expression
4 changes: 2 additions & 2 deletions Get-Transpiler.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#region Piecemeal [ 0.3.2 ] : Easy Extensible Plugins for PowerShell
# Install-Module Piecemeal -Scope CurrentUser
# Import-Module Piecemeal -Force
# Install-Piecemeal -ExtensionNoun 'Transpiler' -ExtensionPattern '\.psx\.ps1' -ExtensionTypeName 'PipeScript.Transpiler' -OutputPath '.\Get-Transpiler.ps1'
# Install-Piecemeal -ExtensionNoun 'Transpiler' -ExtensionPattern '\.psx\.ps1$' -ExtensionTypeName 'PipeScript.Transpiler' -OutputPath '.\Get-Transpiler.ps1'
function Get-Transpiler
{
<#
Expand Down Expand Up @@ -170,7 +170,7 @@ function Get-Transpiler
)

begin {
$TranspilerPattern = '\.psx\.ps1'
$TranspilerPattern = '\.psx\.ps1$'
$TranspilerTypeName = 'PipeScript.Transpiler'
#region Define Inner Functions
function WhereExtends {
Expand Down
5 changes: 4 additions & 1 deletion Invoke-PipeScript.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,10 @@
elseif ($script:TypeAcceleratorsList -notcontains $transpilerStepName -and $transpilerStepName -notin 'Ordered') {
$psCmdlet.WriteError(
[Management.Automation.ErrorRecord]::new(
[exception]::new("Unable to find a transpiler for [$TranspilerStepName]")
[exception]::new("Unable to find a transpiler for [$TranspilerStepName]"),
'Transpiler.Not.Found',
'ParserError',
$command
)
)

Expand Down
3 changes: 2 additions & 1 deletion Join-PipeScript.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ function Join-PipeScript
if ($BlockType -contains 'param') {
foreach ($combined in $AllScriptBlocks.Ast.ParamBlock) {
if (-not $combined.Parent.Extent) { continue }
$combined.Parent.Extent.ToString().Substring(0, $combined.Extent.StartOffset)
$offsetDifference = $combined.Extent.StartOffset - $combined.Parent.Extent.StartOffset
$combined.Parent.Extent.ToString().Substring(0, $offsetDifference) -replace '^[\r\n]+\{'
}
}
# Start the param block
Expand Down
245 changes: 245 additions & 0 deletions New-PipeScript.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
function New-PipeScript {
<#
.Synopsis
Creates new PipeScript.
.Description
Creates new PipeScript and PowerShell ScriptBlocks.
.EXAMPLE
New-PipeScript -Parameter @{a='b'}
#>
[Alias('New-ScriptBlock')]
param(
# Defines one or more parameters for a ScriptBlock.
# Parameters can be defined in a few ways:
# * As a ```[Collections.Dictionary]``` of Parameters
# * As the ```[string]``` name of an untyped parameter.
# * As an ```[Object[]]```.
# * As a ```[ScriptBlock]```
[Parameter(ValueFromPipelineByPropertyName)]
[ValidateScript({
$validTypeList = [System.Collections.IDictionary],[System.String],[System.Object[]],[System.Management.Automation.ScriptBlock]
$thisType = $_.GetType()
$IsTypeOk =
$(@( foreach ($validType in $validTypeList) {
if ($_ -as $validType) {
$true;break
}
}))
if (-not $isTypeOk) {
throw "Unexpected type '$(@($thisType)[0])'. Must be 'System.Collections.IDictionary','string','System.Object[]','scriptblock'."
}
return $true
})]

$Parameter,

# The dynamic parameter block.
[Parameter(ValueFromPipelineByPropertyName)]
[ValidateScript({
if ($_.Ast.DynamicParamBlock -or $_.Ast.BeginBlock -or $_.Ast.ProcessBlock) {
throw "ScriptBlock should not have any named blocks"
}
return $true
})]
[ValidateScript({
if ($_.Ast.ParamBlock.Parameters.Count) {
throw "ScriptBlock should not have parameters"
}
return $true
})]
[Alias('DynamicParameterBlock')]
[ScriptBlock]
$DynamicParameter,
# The begin block.
[Parameter(ValueFromPipelineByPropertyName)]
[ValidateScript({
if ($_.Ast.DynamicParamBlock -or $_.Ast.BeginBlock -or $_.Ast.ProcessBlock) {
throw "ScriptBlock should not have any named blocks"
}
return $true
})]
[ValidateScript({
if ($_.Ast.ParamBlock.Parameters.Count) {
throw "ScriptBlock should not have parameters"
}
return $true
})]
[Alias('BeginBlock')]
[ScriptBlock]
$Begin,
# The process block.
[Parameter(ValueFromPipelineByPropertyName)]
[ValidateScript({
if ($_.Ast.DynamicParamBlock -or $_.Ast.BeginBlock -or $_.Ast.ProcessBlock) {
throw "ScriptBlock should not have any named blocks"
}
return $true
})]
[ValidateScript({
if ($_.Ast.ParamBlock.Parameters.Count) {
throw "ScriptBlock should not have parameters"
}
return $true
})]
[Alias('ProcessBlock')]
[ScriptBlock]
$Process,
# The end block.
[Parameter(ValueFromPipelineByPropertyName)]
[ValidateScript({
if ($_.Ast.DynamicParamBlock -or $_.Ast.BeginBlock -or $_.Ast.ProcessBlock) {
throw "ScriptBlock should not have any named blocks"
}
return $true
})]
[ValidateScript({
if ($_.Ast.ParamBlock.Parameters.Count) {
throw "ScriptBlock should not have parameters"
}
return $true
})]
[Alias('EndBlock')]
[ScriptBlock]
$End,

# The script header.
[Parameter(ValueFromPipelineByPropertyName)]
[string]
$Header
)
begin {
$ParametersToCreate = [Ordered]@{}
$allDynamicParameters = @()
$allBeginBlocks = @()
$allEndBlocks = @()
$allProcessBlocks = @()
$allHeaders = @()
}
process {
if ($parameter) {
# The -Parameter can be a dictionary of parameters.
if ($Parameter -is [Collections.IDictionary]) {
$parameterType = ''
# If it is, walk thur each parameter in the dictionary
foreach ($EachParameter in $Parameter.GetEnumerator()) {
# Continue past any parameters we already have
if ($ParametersToCreate.Contains($EachParameter.Key)) {
continue
}
# If the parameter is a string and the value is not a variable
if ($EachParameter.Value -is [string] -and $EachParameter.Value -notlike '*$*') {
$parameterName = $EachParameter.Key
$ParametersToCreate[$EachParameter.Key] =
@(
$parameterAttribute = "[Parameter(ValueFromPipelineByPropertyName)]"
$parameterType
'$' + $parameterName
) -ne ''
}
# If the value is a string and the value contains variables
elseif ($EachParameter.Value -is [string]) {
# embed it directly.
$ParametersToCreate[$EachParameter.Key] = $EachParameter.Value
}
# If the value is a ScriptBlock
elseif ($EachParameter.Value -is [ScriptBlock]) {
# Embed it
$ParametersToCreate[$EachParameter.Key] =
# If there was a param block on the script block
if ($EachParameter.Value.Ast.ParamBlock) {
# embed the parameter block (except for the param keyword)
$EachParameter.Value.Ast.ParamBlock.Extent.ToString() -replace
'^[\s\r\n]param(' -replace ')[\s\r\n]$'
} else {
# Otherwise
$EachParameter.Value.ToString() -replace
"\`$$($eachParameter.Key)[\s\r\n]$" -replace # Replace any trailing variables
'param()[\s\r\n]{0,}$' # then replace any empty param blocks.
}
}
elseif ($EachParameter.Value -is [Object[]]) {
$ParametersToCreate[$EachParameter.Key] =
$EachParameter.Value -join [Environment]::Newline
}
}
} elseif ($Parameter -is [string]) {
$ParametersToCreate[$Parameter] = @(
"[Parameter(ValueFromPipelineByPropertyName)]"
"`$$Parameter"
)
} elseif ($Parameter -is [Object[]]) {
$currentParam = @()
$currentParamName = ''
foreach ($EachParameter in $Parameter) {
if ($EachParameter -is [string] -and -not $EachParameter.Contains(' ')) {
if ($currentParam) {
$ParametersToCreate[$currentParamName] = $currentParam
$currentParam = @()
$currentParamName = ''
}
$currentParam += "`$$EachParameter"
$currentParamName = $EachParameter
} elseif ($EachParameter -is [string] -and $EachParameter.Contains(' ')) {
$currentParam = @(
if ($EachParameter.Contains("`n")) {
"<#" + [Environment]::newLine + $EachParameter + [Environment]::newLine + '#>'
} else {
"# $EachParameter"
}
) + $currentParam
} elseif ($EachParameter -is [type]) {
$currentParam += "[$($EachParameter.Fullname)]"
}
}
if ($currentParamName) {
$ParametersToCreate[$currentParamName] = $currentParam
}
}
}
if ($header) {
$allHeaders += $Header
}
if ($DynamicParameter) {
$allDynamicParameters += $DynamicParameter
}
if ($Begin) {
$allBeginBlocks += $begin
}
if ($process) {
$allProcessBlocks += $process
}
if ($end) {
$allEndBlocks += $end
}

}
end {
$newParamBlock =
"param(" + [Environment]::newLine +
$(@(foreach ($toCreate in $ParametersToCreate.GetEnumerator()) {
$toCreate.Value -join [Environment]::NewLine
}) -join (',' + [Environment]::NewLine)) +
[Environment]::NewLine +
')'
$createdScriptBlock = [scriptblock]::Create("
$($allHeaders -join [Environment]::Newline)
$newParamBlock
$(if ($allDynamicParameters) {
@(@("dynamicParam {") + $allDynamicParameters + '}') -join [Environment]::Newline
})
$(if ($allBeginBlocks) {
@(@("begin {") + $allBeginBlocks + '}') -join [Environment]::Newline
})
$(if ($allProcessBlocks) {
@(@("process {") + $allProcessBlocks + '}') -join [Environment]::Newline
})
$(if ($allEndBlocks -and -not $allBeginBlocks -and -not $allProcessBlocks) {
$allEndBlocks -join [Environment]::Newline
} elseif ($allEndBlocks) {
@(@("end {") + $allEndBlocks + '}') -join [Environment]::Newline
})
")
$createdScriptBlock
}
}

Loading