Skip to content

Instantly share code, notes, and snippets.

View medium-todos-objs.ps1
... # previous param definition
& {
... # previous class and enum definitions
foreach ($file in $files) {
$lines = Get-Content $file
foreach ($i in 1..$lines.Count) {
if ($lines[$i] -match "TODO: \(([^)]+)\) (.*)$") {
# parse prioritized ToDo
View medium-todos-files.ps1
Push-Location $RepoRoot
$files = Get-ChildItem . -File -Recurse `
| % FullName `
| ? {$_ -ne $PSCommandPath} `
| Resolve-Path -Relative
Pop-Location
View medium-todos-define.txt
TODO: (HIGH) Remove hard-coded secret
TODO: (LOW) Upgrade to LTS version
TODO: I think this can be cleaner
View medium-todos-output.ps1
enum Priority {
Low = 3
Medium = 2
High = 1
}
class ToDo {
[string] $FilePath
[Nullable[Priority]] $Priority
[int] $Line
View medium-todos-params.ps1
Param(
# Path to the repo containing TODO-annotated files
[Parameter(Mandatory)]
[ValidateScript({Test-Path $_ -PathType Container})]
[string]$RepoRoot
)
View medium-requirements-formatting.out
Method Lifecycle Name Date
------ --------- ---- ----
Test Start Resource 1 6/12/2019 12:00:25 PM
Test Stop Resource 1 6/12/2019 12:00:25 PM
Set Start Resource 1 6/12/2019 12:00:25 PM
Set Stop Resource 1 6/12/2019 12:00:26 PM
Validate Start Resource 1 6/12/2019 12:00:26 PM
Validate Stop Resource 1 6/12/2019 12:00:26 PM
Test Start Resource 2 6/12/2019 12:00:26 PM
Test Stop Resource 2 6/12/2019 12:00:26 PM
View medium-requirements-formatting.ps1
$requirements | Invoke-Requirement | Format-Table -AutoSize
View medium-requirements-invokelogging.ps1
enum Method {Test; Set; Validate}
enum Lifecycle {Start; Stop}
class RequirementEvent {
[Method] $Method
[Lifecycle] $Lifecycle
[string] $Name
[datetime] $Date = (Get-Date)
RequirementEvent($name, $method, $lifecycle) {
View medium-requirements-invokesimple.ps1
function Invoke-Requirement {
[CmdletBinding()]
Param(
[Parameter(Mandatory, ValueFromPipeline)]
[ValidateNotNullOrEmpty()]
[Requirement[]]$Requirement
)
process {
$result = &$_.Test