View Single Post
Old 10-17-2006   #1 (permalink)
klumsy@xtra.co.nz


 
 

formatting command syntax like get-help or get-command

i'm trying to work out how to format the maml help objects like
get-help or get-command does, in the example same format.. here is my
code so far, however in all cases it doesn't behave exactly the same,
in some cases it doesn't put enough brackets around, and in cases when
there is a parameter without a value, it puts double brackets. i've
looked in the help.format.ps1xml to try to work out hte same logic but
still got a few things wrong. so i figured i'd put it out here for the
community and MS people to look at.. the benefit is when its done i'll
release and blog my whole mamlhelp -> richHTML code, that i'll be
incorporating into powershell analyzer..

#region syntax
$help = get-Help get-Command -full
($help.syntax) | % { $_.syntaxitem } |
% { $str = "";$("$($_.name) "
$_ | % { $_.parameter |
% { $myp = $_;$_.psobject |
% {
if ($_.properties["required"].value -ne "true") { "[" }
if (($_.properties["position"].value -ne $()) -and
($_.properties["position"].value -ne "") ) { "[" }
"-";$_.properties["name"].value
if (($_.properties["position"].value -ne $()) -and
($_.properties["position"].value -ne "")) { "]" }

if ($_.properties["parametervalue"] -ne $() )
{
'<' + $_.properties["parametervalue"].value + '>'
}
if ($_.properties["parametervaluegroup"] -ne $() )
{
"{"
$_.properties["parametervaluegroup"].value |
% {
$i=0; $out=""; foreach($a in $_.parametervalue)
{ if($i -gt 0)
{ $out = $out + " | "; }
$out = $out + "<" + $a + ">"; $i = $i + 1; }
$out;
}
"}"
}
if ($_.properties["required"].value -ne "true") { "] " }
}
}
}
) | % { $str = $str + $_ } ; $str
}
#endregion

My System SpecsSystem Spec