Skip to content

Instantly share code, notes, and snippets.

@rfennell
Created August 23, 2016 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfennell/02d0e0981d99a5ee34d8e07fe72b4dc4 to your computer and use it in GitHub Desktop.
Save rfennell/02d0e0981d99a5ee34d8e07fe72b4dc4 to your computer and use it in GitHub Desktop.
How to add filters to release note generation
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)"
@rfennell
Copy link
Author

For discussion of the background to this sample see Issue #35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment