Created
August 23, 2016 11:01
-
-
Save rfennell/02d0e0981d99a5ee34d8e07fe72b4dc4 to your computer and use it in GitHub Desktop.
How to add filters to release note generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-Mode | |
{ | |
Param( | |
$line | |
) | |
$returnvalue = "" | Select-Object -Property mode, skipLogic | |
$mode = [Mode]::BODY | |
if ($line.StartsWith("@@WILOOP@@")) {$mode = [Mode]::WI} | |
if ($line.StartsWith("@@CSLOOP@@")) {$mode = [Mode]::CS} | |
if ($line.StartsWith("@@BUILDLOOP@@")) {$mode = [Mode]::BUILD} | |
$returnvalue.Mode = $mode | |
if ($mode -ne [Mode]::BODY) | |
{ | |
#check if there is any filter logic | |
$array = $line -split ' ',2 | |
if ( $array[1] -eq $null) | |
{ | |
$returnvalue.skipLogic = " " # use a space as command | |
} else | |
{ | |
$returnvalue.skipLogic = $array[1] | |
} | |
} | |
$returnvalue | |
} | |
function Render() { | |
[CmdletBinding()] | |
param ( [parameter(ValueFromPipeline = $true)] [string] $str) | |
#buggy in V4 seems ok in older and newer | |
#$ExecutionContext.InvokeCommand.ExpandString($str) | |
"@`"`n$str`n`"@" | iex | |
} | |
Add-Type -TypeDefinition @" | |
public enum Mode | |
{ | |
BODY, | |
WI, | |
CS, | |
BUILD | |
} | |
"@ | |
"A line with a filter" | |
$myval = 'hello' | |
$line = "@@WILOOP@@ ('`$myval' -eq 'hello') " | |
$x = Get-Mode $line | |
" The line mode is - $($x.mode)" | |
" The filter logic is - $($x.skiplogic)" | |
" The render does not exec the filter test, just expands the variable - $($x.skipLogic | render)" | |
" The invoke does evaluates the filter test - $(Invoke-Expression $x.skipLogic)" | |
"A line with no filter" | |
$myval = 'hello' | |
$line = "@@WILOOP@@" | |
$x = Get-Mode $line | |
" The line mode is - $($x.mode)" | |
" The filter logic is - $($x.skiplogic)" | |
" The render does not exec the filter test, just expands the variable - $($x.skipLogic | render)" | |
" The invoke does evaluates the filter test - $(Invoke-Expression $x.skipLogic)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For discussion of the background to this sample see Issue #35