Skip to content

Commit

Permalink
Merge pull request #10 from StartAutomating/OutSplatFixes
Browse files Browse the repository at this point in the history
Out splat fixes
  • Loading branch information
StartAutomating authored Oct 17, 2021
2 parents 81dbe39 + 551ed05 commit 32310b1
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 398 deletions.
Binary file added Assets/Splatter-16x9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assets/Splatter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 91 additions & 11 deletions Out-Splat.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
Initialize-Splatter
.Example
Out-Splat -CommandName Get-Command
.Example
Out-Splat -FunctionName Get-MyProcess -Example Get-MyProcess -CommandName Get-Process -DefaultParameter @{
Id = '$pid'
} -ExcludeParameter *
#>
[CmdletBinding(DefaultParameterSetName='JustTheSplatter')]
[OutputType([ScriptBlock])]
Expand Down Expand Up @@ -84,11 +88,39 @@
[string]
$Description,

# One or more examples.
# This is used to make comment-based help in a generated function.
[Parameter(ValueFromPipelineByPropertyName,ParameterSetName='FunctionalSplatter')]
[Alias('Examples')]
[string[]]
$Example,

# One or more links.
# This is used to make comment-based help in a generated function.
[Parameter(ValueFromPipelineByPropertyName,ParameterSetName='FunctionalSplatter')]
[Alias('Links')]
[string[]]
$Link,

# Some notes.
# This is used to make comment-based help in a generated function.
[Parameter(ValueFromPipelineByPropertyName,ParameterSetName='FunctionalSplatter')]
[Alias('Notes')]
[string]
$Note,

# The CmdletBinding attribute for a new function
[Parameter(ValueFromPipelineByPropertyName,ParameterSetName='FunctionalSplatter')]
[string]
$CmdletBinding,

# The [OutputType()] of a function.
# If the type resolves to a [type], it's value will be provided as a [type].
# Otherwise, it will be provided as a [string]
[Parameter(ValueFromPipelineByPropertyName,ParameterSetName='FunctionalSplatter')]
[string[]]
$OutputType,

# A set of additional parameter declarations.
# The keys are the names of the parameters, and the values can be a type and a string containing parameter binding and inline help.
[Parameter(ValueFromPipelineByPropertyName,ParameterSetName='FunctionalSplatter')]
Expand Down Expand Up @@ -441,23 +473,62 @@ $parameterHelp
$paramBlock = $paramBlockParts -join (',' + ([Environment]::NewLine * 2))
if (-not $Synopsis) {
$Synopsis = "Wraps $CommandName"
}
if (-not $Synopsis) {
$Synopsis = "Wraps $CommandName"
}
if (-not $Description) {
$Description = "Calls $CommandName, using splatting"
}
if (-not $Description) {
$Description = "Calls $CommandName, using splatting"
}
$exampleText =
if ($Example) {
@(foreach ($ex in $Example) {
" .Example"
foreach ($ln in $ex -split '(?>\r\n|\n)') {
" $ln"
}
}) -join [Environment]::NewLine
} else { ''}
$noteText =
if ($Note) {
@(
" .Notes"
foreach ($ln in $Note -split '(?>\r\n|\n)') {
" $ln"
}
) -join [Environment]::NewLine
} else { ''}
$linkText =
if ($Link) {
@(foreach ($lnk in $Link) {
" .Link"
" $lnk"
}) -join [Environment]::NewLine
} else { @"
.Link
$CommandName
"@
}
[ScriptBlock]::Create("function $FunctionName
{
<#
.Synopsis
$Synopsis
.Description
$Description
.Link
$CommandName
$Description$(
if ($exampleText) { [Environment]::NewLine + $exampleText}
)$(
if ($linkText) { [Environment]::NewLine + $linkText}
)$(
if ($NoteText) { [Environment]::NewLine + $noteText}
)
#>$(if ($CmdletBinding) {
if ($CmdletBinding -like "*CmdletBinding*") {
[Environment]::NewLine + (' '*4) + $CmdletBinding
Expand All @@ -466,9 +537,18 @@ if (-not $Description) {
}
} elseif ($originalCmdletBinding) {
[Environment]::NewLine + (' '*4) + $originalCmdletBinding
})
})$(
if ($OutputType) {
[Environment]::NewLine + (' '*4) + '[OutputType(' + @(foreach ($ot in $outputtype) {
if ($ot -as [type]) {"[$ot]"} else { "'$ot'"}
}) -join ',' + ')]'
} else {
[Environment]::NewLine + (' '*4) + '[OutputType([PSObject])]'
}
)
param(
$paramBlock)
$paramBlock
)
process {
$(@(foreach ($line in $coreSplat -split ([Environment]::Newline)) {
Expand Down
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
## Splatter is a simple Splatting toolkit
<div align='center'>
<img src='Assets/Splatter-16x9.png' style='align:center' />
<h1>Simple Scripts to Supercharge Splatting</h1>
</div>

[![Test Build And Publish](https://github.com/StartAutomating/Splatter/actions/workflows/TestBuildAndPublish.yml/badge.svg)](https://github.com/StartAutomating/Splatter/actions/workflows/TestBuildAndPublish.yml)

## Splatter is a simple Splatting toolkit

Splatting is a technique of passing parameters in PowerShell.

Expand Down Expand Up @@ -179,14 +186,14 @@ If you don't need all of the commands, you can use -Verb

### Generating Splatting Code

You can use Out-Splatter to generate code that splats.
You can use Out-Splat to generate code that splats.

Out-Splatter -CommandName Get-Command -DefaultParameter @{Module='Splatter';CommandType='Alias'} | Invoke-Expression
Out-Splat -CommandName Get-Command -DefaultParameter @{Module='Splatter';CommandType='Alias'} | Invoke-Expression

You can use also use Out-Splatter to generate whole functions, including help.

$scriptBlock =
Out-Splatter -FunctionName Get-SplatterAlias -CommandName Get-Command -DefaultParameter @{
Out-Splat -FunctionName Get-SplatterAlias -CommandName Get-Command -DefaultParameter @{
Module='Splatter';CommandType='Alias'
} -ExcludeParameter * -Synopsis 'Gets Splatter Aliases' -Description 'Gets aliases from the module Splatter'
. ([ScriptBlock]::Create($scriptBlock))
Expand Down
8 changes: 7 additions & 1 deletion Splatter.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Copyright = '2019-2021 Start-Automating'
RootModule = 'Splatter.psm1'
Description = 'Simple Scripts to Supercharge Splatting'
ModuleVersion = '0.5.2'
ModuleVersion = '0.5.3'
AliasesToExport = '*'
VariablesToExport = '*'
GUID = '033f35ed-f8a7-4911-bb62-2691f505ed43'
Expand All @@ -12,8 +12,14 @@
PSData = @{
ProjectURI = 'https://github.com/StartAutomating/Splatter'
LicenseURI = 'https://github.com/StartAutomating/Splatter/blob/master/LICENSE'
IconURI = 'https://raw.githubusercontent.com/StartAutomating/Splatter/master/Assets/Splatter.png'
Tags = 'Splatting'
ReleaseNotes = @'
### 0.5.3:
* Out-Splat now supports -Examples, -Links, -Notes, and -OutputTypes (Issue #9)
* Adding logo
* Documentation updates.
### 0.5.2:
* Improved pipeline support (Fixes #6)
* Out-Splat -CrossStream will now output all streams in generated commands, not just error and output.
Expand Down
Loading

0 comments on commit 32310b1

Please sign in to comment.