# encoding: ascii
# api: powershell
# title: Test-CommandValidation
# description: validate cmdlet and function
# version: 0.1
# type: function
# author: Walid Toumi
# license: CC0
# function: Test-CommandValidation
# x-poshcode-id: 3675
# x-archived: 2012-10-21T16:42:15
# x-published: 2012-10-01T23:06:00
#
#
#############################################################
#
# PS II> Test-CommandValidation -command get-process | fl
# VerbNounConvention : True
# ReservedKeyWords : True
# VerbConvention : True
#
# author: Walid Toumi
#############################################################
function Test-CommandValidation {
param($Command,[switch]$SimpleForm)
$keys = man key |
Select-String "(\S+)(?=\s{5,}about_*)" |
select -expand Matches |
select -expand value
$verbNounConvention = $verbconvention = $reservedkeywords = $false
$verb,$noun = $Command.Split('-')
if($noun) {
$verbNounConvention = $true
if( (get-verb $verb) ) { $verbconvention = $true }
if($keys -contains $noun) { $reservedkeywords = $true }
}
else {
$reservedkeywords = $verbconvention = $null
}
$objPS=new-object PSObject -prop @{
VerbNounConvention = $verbNounConvention
VerbConvention = $verbconvention
ReservedKeyWords = $reservedkeywords
}
if($SimpleForm) {
switch($objPS) {
{!$_.ReservedKeyWords -and $_.VerbConvention -and $_.VerbNounConvention}
{Write-Host "PASS !!" -ForegroundColor green}
{!$_.VerbConvention -and !$_.VerbConvention -and !$_.VerbNounConvention}
{Write-Host "FAIL !!" -ForegroundColor red}
default
{ Write-Host "MAYBE !!" -ForegroundColor DarkYellow }
}
} else {
$objPS
}
}