envman.psm1
. "$PSScriptRoot/utils.ps1" function Get ($Name, $Key) { if (TableExists $Name) { if ($Key) { return (LoadTable $Name)[$Key] } else { return LoadTable $Name } } elseif (!$Name) { Write-Error "No table name provided"; return } else { Write-Error "Table does not exist."; return } } function Set($Name, $Key, $Value) { $Table = Get $Name if (!$Table) { return # error on Get } $Table[$Key] = $Value WriteTable $Name $Table } function New($Name, $Table) { if (!$Name) { Write-Error "No table name provided"; return } if (TableExists $Name) { Write-Error "Table already exists."; return } WriteTable $Name $Table } function Test($Name) { return TableExists $Name } function Del($Name, $Key) { if (TableExists $Name) { if ($Key) { $Table = LoadTable $Name if ($Table.keys -contains $Key) { $Table[$Key] = $null WriteTable $Name $Table } else { Write-Error "Table '$Name' does not have the key '$Key'."; return } } else { DeleteTable $Name } } elseif (!$Name) { Write-Error "No table name provided"; return } else { Write-Error "Table does not exist."; return } } function All { ListTables } |