< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.OpenApi.HelpExtractor
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/OpenApi/HelpExtractor.cs
Tag: Kestrun/Kestrun@0d738bf294e6281b936d031e1979d928007495ff
Line coverage
0%
Covered lines: 0
Uncovered lines: 19
Coverable lines: 19
Total lines: 78
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 34
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 12/12/2025 - 17:27:19 Line coverage: 0% (0/19) Branch coverage: 0% (0/34) Total lines: 78 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd 12/12/2025 - 17:27:19 Line coverage: 0% (0/19) Branch coverage: 0% (0/34) Total lines: 78 Tag: Kestrun/Kestrun@826bf9dcf9db118c5de4c78a3259bce9549f0dcd

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetHelp(...)0%156120%
GetSynopsis(...)0%4260%
GetDescription(...)0%4260%
GetParameterDescription(...)0%110100%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/OpenApi/HelpExtractor.cs

#LineLine coverage
 1using System.Management.Automation;
 2using System.Management.Automation.Language;
 3
 4namespace Kestrun.OpenApi;
 5/// <summary>
 6/// Helper to extract help information from PowerShell functions.
 7/// </summary>
 8public static class HelpExtractor
 9{
 10    /// <summary>
 11    /// Get the parsed comment-based help (CommentHelpInfo) for a PowerShell function
 12    /// using the AST + FunctionDefinitionAst.GetHelpContent().
 13    /// </summary>
 14    public static CommentHelpInfo? GetHelp(this FunctionInfo fn)
 15    {
 016        if (fn.ScriptBlock?.Ast is null)
 17        {
 018            return null;
 19        }
 20
 21        // Case 1: the AST *is already* a FunctionDefinitionAst
 022        if (fn.ScriptBlock.Ast is FunctionDefinitionAst directFuncAst)
 23        {
 024            return directFuncAst.GetHelpContent();
 25        }
 26
 27        // Case 2: the AST is a ScriptBlockAst (or something else),
 28        // and we need to search for the matching FunctionDefinitionAst
 029        if (fn.ScriptBlock.Ast is ScriptBlockAst scriptAst)
 30        {
 031            var funcAst = scriptAst.Find(
 032                ast => ast is FunctionDefinitionAst f &&
 033                       f.Name.Equals(fn.Name, StringComparison.OrdinalIgnoreCase),
 034                searchNestedScriptBlocks: true) as FunctionDefinitionAst;
 35
 036            return funcAst?.GetHelpContent();
 37        }
 38
 39        // Fallback: unknown AST shape
 040        return null;
 41    }
 42
 43    /// <summary>
 44    /// Get the synopsis from the help information.
 45    /// </summary>
 46    /// <param name="help"> The help information to extract the synopsis from. </param>
 47    /// <returns>The synopsis text. </returns>
 48    public static string GetSynopsis(this CommentHelpInfo? help)
 049        => help?.Synopsis?.Trim() ?? string.Empty;
 50
 51    /// <summary>
 52    /// Get the description from the help information.
 53    /// </summary>
 54    /// <param name="help"> The help information to extract the description from. </param>
 55    /// <returns>The description text.</returns>
 56    public static string GetDescription(this CommentHelpInfo? help)
 057        => help?.Description?.Trim() ?? string.Empty;
 58
 59    /// <summary>
 60    /// Get the parameter description from the help information.
 61    /// </summary>
 62    /// <param name="help"> The help information to extract the parameter description from. </param>
 63    /// <param name="name"> The name of the parameter to get the description for. </param>
 64    /// <returns>The parameter description text, or null if not found.</returns>
 65    public static string? GetParameterDescription(this CommentHelpInfo? help, string name)
 66    {
 067        if (help?.Parameters == null || string.IsNullOrEmpty(name))
 68        {
 069            return null;
 70        }
 71        // Parameter names in CommentHelpInfo are stored in uppercase
 072        var key = name.ToUpperInvariant();
 73        // Try to get the parameter description
 074        return help.Parameters.TryGetValue(key, out var text)
 075            ? text?.Trim()
 076            : null;
 77    }
 78}