From 34ddaf4d919bd2c77445ec7105ac5d396a1d9df9 Mon Sep 17 00:00:00 2001 From: jongeller Date: Wed, 30 Sep 2015 14:38:45 -0700 Subject: [PATCH] Updating Get-AllCommands script with requested changes. Indentation and fix to create proper file path for MAML file output. --- .../Docs/Get-AllCommands/Get-AllCommands.ps1 | 1184 ++++++++++------- 1 file changed, 671 insertions(+), 513 deletions(-) diff --git a/tools/Docs/Get-AllCommands/Get-AllCommands.ps1 b/tools/Docs/Get-AllCommands/Get-AllCommands.ps1 index 4664ec2bbb29..cb36ae2468db 100644 --- a/tools/Docs/Get-AllCommands/Get-AllCommands.ps1 +++ b/tools/Docs/Get-AllCommands/Get-AllCommands.ps1 @@ -1,523 +1,681 @@ -function Test-BuildMamlFolder { - - Param - ( - [CmdletBinding()] - [parameter(Mandatory=$true)] - [String] - $MamlFolderPath, - [parameter(Mandatory=$true)] - [String] - $ModuleName - ) - - #$MamlFolderPath = "\\srvua\PSPush2x\Main\DXPowerShellBlue\AGPM_Cmdlets\PSMAML\" - $MamlFileNames = (Get-ChildItem -Path $MamlFolderPath | WHERE { $_.Name -like "*.xml"}).Name - $CmdletCount = 0 - $ParmCount = 0 - $ShortDescCount = 0 - $LongDescCount = 0 - $HelpExCount = 0 - $InputObjectDesccount = 0 - $OutputObjectDesccount = 0 - $MissingContent = 0 - $OutArray = @() - - foreach ($MamlFile in $MamlFileNames) - { - $FullName = $MamlFolderPath + $MamlFile - [xml]$MamlXml = Get-Content $FullName - $CmdletCount += 1 - $WarnCount = 0 - $CmdletName = $MamlXml.command.details.name - $CmdletName = $CmdletName.Trim() - $ShortDescription = $MamlXml.command.details.description.para - - if ($ShortDescription.Length -gt 10 -and $ShortDescription) - { - $ShortDescCount += 1 - } - else - { - if (!$NoWarnings) - { - $OutArray += "No short description for $CmdletName." - $WarnCount += 1 - } - } - - # Long Description - # Updated for PS MAML Files - - $LongDescription = $MamlXml.command.description.para - - if ($LongDescription.Length -gt 10 -and $LongDescription) - { - $LongDescCount += 1 - } - else - { - if (!$NoWarnings) - { - $OutArray += "No long description for $CmdletName." - $WarnCount += 1 - } - - } - - # PS MAML Examples Count Check - #Updated for PS MAML Files - - $MamlExamples = $MamlXml.command.examples.example - - if($MamlExamples) - { - ForEach($Example in $MamlExamples) - { - $ExCount += 1 - if(!$Example.title) - { - $OutArray += "No example title found for an example in $CmdletName." - } - if(!$Example.introduction.para) - { - $OutArray += "No example introduction found for an example in $CmdletName." - } - if(!$Example.code) - { - $OutArray += "No example code found for an example in $CmdletName." - } - - } - } - else - { - $OutArray += "No examples found for $CmdletName." - } - - - #Cmdlet Input Object Description - #Updated for PS MAML Files - - $InputObjects = $MamlXml.command.inputTypes.inputType - if($InputObjects) - { - foreach($InputObj in $InputObjects) - { - $inputObjName = $InputObj.type.name - if ($inputObj.description.para.innertext) - { - $InputObjectDesccount += 1 - } - else - { - if (!$NoWarnings) - { - $OutArray += "No input object description for $inputObjName in $CmdletName" - $WarnCount += 1 - } - } - } - } - - #PS MAML Output Object Description - #Updated for PS MAML Files - $OutPutObjects = $MamlXml.command.returnValues.returnValue - if($OutPutObjects) - { - foreach($outputObj in $OutPutObjects) - { - $outputObjName = $outputObj.type.name - if ($outputObj.description.para.innertext) - { - $OutputObjectDesccount += 1 - } - else - { - if (!$NoWarnings) - { - $OutArray += "No output object description for $outputObjName in $CmdletName" - $WarnCount += 1 - } - } - } - } - # Parameter Descriptions - #Updated for PS MAML Files - $Parameters = $MamlXml.command.parameters.parameter - - foreach ($parm in $Parameters) - { - $ParmCount += 1 - $ParmName = $parm.Name - if ($parm.Description) - { - $ParmDescCount += 1 - } - else - { - if (!$NoWarnings) - { - $OutArray += "No parameter description for $CmdletName -$ParmName." - $WarnCount += 1 - } - } - } - #Evaluates Missing Elements - if ($WarnCount -ne 0) - { - $MissingContent +=1 - } - } - - if($MissingContent -gt 0) - { - $OutFileName = ($MamlFolderPath + " \..\..\..\" + $ModuleName + "_Report_MISSING_CONTENT.txt") - } - else - { - $OutFileName = ($MamlFolderPath + " \..\..\..\" + $ModuleName + "_Report.txt") - } - - - #Computation of Percentage Complete - $fShortDescPercent = "{0:P1}" -f ($ShortDescCount/$CmdletCount) - $fLongDescPercent = "{0:P1}" -f ($LongDescCount/$CmdletCount) - $fExPercent = "{0:P1}" -f ($ExCount/$CmdletCount) - $fParmDescPercent = "{0:P1}" -f ($ParmDescCount/$ParmCount) - $fMissingContentPercent = "{0:P1}" -f ($MissingContent/$CmdletCount) - $fInputObject = "{0:P1}" -f ($InputObjectDesccount/$CmdletCount) - $fOutputObjectDesc = "{0:P1}" -f ($OutputObjectDesccount/$CmdletCount) - - ###Report Output into PowerShell Host - #Header Message - $OutArray += "`nReport Summary" - $OutArray += "--------------" - $OutArray += "Folder Path: $MamlFolderPath" - $OutArray += "Commands: $CmdletCount" - $OutArray += "Parameters: $ParmCount" - - #Short Desc Message - $ShortDescMessage = "Short Descriptions: $ShortDescCount ( $fShortDescPercent )" - if($fShortDescPercent -eq '100.0 %'){ $OutArray += $ShortDescMessage } - else - { $OutArray += $ShortDescMessage } - - #Long Desc Message - $LongDescMessage = "Long Descriptions: $LongDescCount ( $fLongDescPercent )" - if($fLongDescPercent -eq '100.0 %'){$OutArray += "Long Descriptions: $LongDescCount ( $fLongDescPercent )" } - else - { $OutArray += $LongDescMessage } - - #Example Message - $ExamplesMessage = "Examples: $ExCount ( $fExPercent )" - if($fExPercent -eq '100.0 %'){$OutArray += $ExamplesMessage } - else - { $OutArray += $ExamplesMessage } - $OutArray += " Minimum Required: $CmdletCount" - - #Input Object Message - $InputObjectMessage = "Input Objects: $InputObjectDesccount ( $fInputObject )" - if($fInputObject -eq '100.0 %'){ $OutArray += $InputObjectMessage } - else - { $OutArray += $InputObjectMessage } - - #Output Object Message - $OutputObjectMessage = "Output Object: $OutputObjectDesccount ( $fOutputObjectDesc )" - if($fOutputObjectDesc -eq '100.0 %'){ $OutArray += $OutputObjectMessage } - else - { $OutArray += $OutputObjectMessage } - - #Parameter Messaage - $ParameterMessage = "Parameter Descriptions: $ParmDescCount ( $fParmDescPercent )" - if($fParmDescPercent -eq '100.0 %'){ $OutArray += $ParameterMessage } - else - { $OutArray += $ParameterMessage } - - #Error & Closing Message - $OutArray += "Number of cmdlets missing content: $MissingContent ( $fMissingContentPercent )" - $OutArray += "--------------" - $OutArray | Out-File -FilePath $OutFileName +function Test-BuildMamlFolder { + + Param + ( + [CmdletBinding()] + [parameter(Mandatory=$true)] + [String] + $MamlFolderPath, + [parameter(Mandatory=$true)] + [String] + $ModuleName, + [parameter(Mandatory=$false)] + [string[]] + $MissingCommands + ) + + #$MamlFolderPath = "\\srvua\PSPush2x\Main\DXPowerShellBlue\AGPM_Cmdlets\PSMAML\" + $MamlFileNames = (Get-ChildItem -Path $MamlFolderPath | WHERE { $_.Name -like "*.xml"}).Name + + $CmdletCount = 0 + $ParmCount = 0 + $ShortDescCount = 0 + $LongDescCount = 0 + $HelpExCount = 0 + $InputObjectDesccount = 0 + $OutputObjectDesccount = 0 + $MissingContent = 0 + + $jsonObject = New-Object -TypeName psobject + $jsonObject | Add-Member -MemberType NoteProperty -Name "ModuleHelpFound" -Value "true" + + $OutArray = @() + if($MissingCommands) + { + $array = $MissingCommands.Split(',') + $missingCommandsJsonObject = New-Object -TypeName psobject + + foreach($missingCommand in $array) + { + $missingCommandsJsonObject | Add-Member -MemberType NoteProperty -Name $missingCommand -Value 0 -Force + } + + $jsonObject | Add-Member -MemberType NoteProperty -Name "MissingCommands" -Value $missingCommandsJsonObject -Force + } + + foreach ($MamlFile in $MamlFileNames) + { + + $internalJsonObject = New-Object -TypeName psobject + + $FullName = $MamlFolderPath + $MamlFile + + [xml]$MamlXml = Get-Content $FullName + + $CmdletCount += 1 + $WarnCount = 0 + + $CmdletName = $MamlXml.command.details.name + $CmdletName = $CmdletName.Trim() + + + # Short Description + # Updated for PS MAML Files + + $ShortDescription = $MamlXml.command.details.description.para + + if ($ShortDescription.Length -gt 10 -and $ShortDescription) + { + $ShortDescCount += 1 + } + else + { + if (!$NoWarnings) + { + $OutArray += "No short description for $CmdletName." + $WarnCount += 1 + $internalJsonObject | Add-Member -MemberType NoteProperty -Name 'ShortDescription' -value 1 -Force + + } + } + + # Long Description + # Updated for PS MAML Files + + $LongDescription = $MamlXml.command.description.para + if ($LongDescription.Length -gt 10 -and $LongDescription) + { + $LongDescCount += 1 + } + else + { + if (!$NoWarnings) + { + $OutArray += "No long description for $CmdletName." + $WarnCount += 1 + $internalJsonObject | Add-Member -MemberType NoteProperty -Name 'LongDescription' -value 1 -Force + } + } + + # PS MAML Examples Count Check + #Updated for PS MAML Files + + $MamlExamples = $MamlXml.command.examples.example + + if($MamlExamples) + { + $ExNumber = 0 + ForEach($Example in $MamlExamples) + { + $ExCount += 1 + $ExNumber += 1 + $ExampleNumber = "Example" + $ExNumber + + if(!$Example.title) + { + $OutArray += "No example title found for an example in $CmdletName." + $internalJsonObject | Add-Member -MemberType NoteProperty -Name ($ExampleNumber + "_Title") -value 1 -Force + } + if(!$Example.introduction.para) + { + $OutArray += "No example introduction found for an example in $CmdletName." + $internalJsonObject | Add-Member -MemberType NoteProperty -Name ($ExampleNumber + "_Introduction") -value 3 -Force + } + if(!$Example.code) + { + $OutArray += "No example code found for an example in $CmdletName." + $internalJsonObject | Add-Member -MemberType NoteProperty -Name ($ExampleNumber + "_Code") -value 1 -Force + } + } + } + else + { + $OutArray += "No examples found for $CmdletName." + $internalJsonObject | Add-Member -MemberType NoteProperty -Name "Examples" -value 0 -Force + } + + #Cmdlet Input Object Description + #Updated for PS MAML Files + $InputObjects = $MamlXml.command.inputTypes.inputType + + if($InputObjects) + { + foreach($InputObj in $InputObjects) + { + $inputObjName = $InputObj.type.name + if ($inputObj.description.para.innertext) + { + $InputObjectDesccount += 1 + } + else + { + if (!$NoWarnings) + { + $OutArray += "No input object description for $inputObjName in $CmdletName" + $internalJsonObject | Add-Member -MemberType NoteProperty -Name "InputObject" -value 1 -Force + $WarnCount += 1 + } + } + } + } + + + #PS MAML Output Object Description + #Updated for PS MAML Files + + $OutPutObjects = $MamlXml.command.returnValues.returnValue + if($OutPutObjects) + { + foreach($outputObj in $OutPutObjects) + { + $outputObjName = $outputObj.type.name + if ($outputObj.description.para.innertext) + { + $OutputObjectDesccount += 1 + } + else + { + if (!$NoWarnings) + { + $OutArray += "No output object description for $outputObjName in $CmdletName" + $WarnCount += 1 + $internalJsonObject | Add-Member -MemberType NoteProperty -Name "OutputObject" -value 1 -Force + } + } + } + } + + # Parameter Descriptions + #Updated for PS MAML Files + $Parameters = $MamlXml.command.parameters.parameter + + foreach ($parm in $Parameters) + { + $ParmCount += 1 + $ParmName = $parm.Name + if ($parm.Description) + { + $ParmDescCount += 1 + } + else + { + if (!$NoWarnings) + { + $OutArray += "No parameter description for $CmdletName -$ParmName." + $WarnCount += 1 + $internalJsonObject | Add-Member -MemberType NoteProperty -Name "Parameter_$ParmName" -value 1 -Force + } + } + } + + #Evaluates Missing Elements + + if ($WarnCount -ne 0) + { + $MissingContent +=1 + $jsonObject | Add-Member -MemberType NoteProperty -Value $internalJsonObject -Name $CmdletName -Force + } + } + + if($MissingContent -gt 0) + { + $OutFileName = ($MamlFolderPath + " \..\..\..\" + $ModuleName + "_Report_MISSING_CONTENT.txt") + } + else + { + $OutFileName = ($MamlFolderPath + " \..\..\..\" + $ModuleName + "_Report.txt") + } + + #Computation of Percentage Complete + $fShortDescPercent = "{0:P1}" -f ($ShortDescCount/$CmdletCount) + $fLongDescPercent = "{0:P1}" -f ($LongDescCount/$CmdletCount) + $fExPercent = "{0:P1}" -f ($ExCount/$CmdletCount) + $fParmDescPercent = "{0:P1}" -f ($ParmDescCount/$ParmCount) + $fMissingContentPercent = "{0:P1}" -f ($MissingContent/$CmdletCount) + $fInputObject = "{0:P1}" -f ($InputObjectDesccount/$CmdletCount) + $fOutputObjectDesc = "{0:P1}" -f ($OutputObjectDesccount/$CmdletCount) + + ###Report Output into PowerShell Host + #Header Message + $OutArray += "`nReport Summary" + $OutArray += "--------------" + $OutArray += "Folder Path: $MamlFolderPath" + $OutArray += "Commands: $CmdletCount" + $OutArray += "Parameters: $ParmCount" + + #Short Desc Message + $ShortDescMessage = "Short Descriptions: $ShortDescCount ( $fShortDescPercent )" + if($fShortDescPercent -eq '100.0 %') + { + $OutArray += $ShortDescMessage + } + else + { + $OutArray += $ShortDescMessage + } + + #Long Desc Message + $LongDescMessage = "Long Descriptions: $LongDescCount ( $fLongDescPercent )" + if($fLongDescPercent -eq '100.0 %') + { + $OutArray += "Long Descriptions: $LongDescCount ( $fLongDescPercent )" + } + else + { + $OutArray += $LongDescMessage + } + + #Example Message + $ExamplesMessage = "Examples: $ExCount ( $fExPercent )" + if($fExPercent -eq '100.0 %') + { + $OutArray += $ExamplesMessage + } + else + { + $OutArray += $ExamplesMessage + } + $OutArray += " Minimum Required: $CmdletCount" + + #Input Object Message + $InputObjectMessage = "Input Objects: $InputObjectDesccount ( $fInputObject )" + if($fInputObject -eq '100.0 %') + { + $OutArray += $InputObjectMessage + } + else + { + $OutArray += $InputObjectMessage + } + + #Output Object Message + $OutputObjectMessage = "Output Object: $OutputObjectDesccount ( $fOutputObjectDesc )" + if($fOutputObjectDesc -eq '100.0 %') + { + $OutArray += $OutputObjectMessage + } + else + { + $OutArray += $OutputObjectMessage + } + + #Parameter Messaage + $ParameterMessage = "Parameter Descriptions: $ParmDescCount ( $fParmDescPercent )" + if($fParmDescPercent -eq '100.0 %') + { + $OutArray += $ParameterMessage + } + else + { + $OutArray += $ParameterMessage + } + + #Error & Closing Message + $OutArray += "Number of cmdlets missing content: $MissingContent ( $fMissingContentPercent )" + $OutArray += "--------------" + $OutArray | Out-File -FilePath $OutFileName + + if(($MissingCommands.Count -gt 0) -or ($MissingContent -gt 0)) + { + $OutFileName = ($MamlFolderPath + " \..\..\..\" + $ModuleName + ".json") + $jsonObject | ConvertTo-Json -Depth 10 | Out-file $OutFileName + } } function Split-HelpFiles { - [Cmdletbinding()] - Param - ( - [parameter(Mandatory=$true)] - [String] - $InputXML, - - [parameter(Mandatory=$true)] - [String] - $OutputPath - ) - - $namespace = @{command="http://schemas.microsoft.com/maml/dev/command/2004/10"; maml="http://schemas.microsoft.com/maml/2004/10"; dev="http://schemas.microsoft.com/maml/dev/2004/10"} - - if (!(test-path $OutputPath)) { mkdir $OutputPath } - if (dir $InputXML | select-string "