()
| 57 | } |
| 58 | |
| 59 | func (h *shellCallHandler) MainHelp() string { |
| 60 | var doc ShellDoc |
| 61 | |
| 62 | def := h.GetDef(nil) |
| 63 | |
| 64 | // Group functions by source module. |
| 65 | type moduleGroup struct { |
| 66 | name string // module name ("" for core) |
| 67 | short string // module description |
| 68 | fns []*modFunction |
| 69 | } |
| 70 | |
| 71 | // Collect functions into groups, preserving encounter order. |
| 72 | groups := make(map[string]*moduleGroup) |
| 73 | var order []string |
| 74 | |
| 75 | constr := def.MainObject.AsObject.Constructor |
| 76 | if !constr.HasRequiredArgs() { |
| 77 | for _, fn := range def.MainObject.AsFunctionProvider().GetFunctions() { |
| 78 | if isHiddenFunction(fn.CmdName()) { |
| 79 | continue |
| 80 | } |
| 81 | src := fn.SourceModuleName |
| 82 | g, ok := groups[src] |
| 83 | if !ok { |
| 84 | g = &moduleGroup{name: src} |
| 85 | groups[src] = g |
| 86 | order = append(order, src) |
| 87 | } |
| 88 | g.fns = append(g.fns, fn) |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | // Fill in module descriptions from dependencies. |
| 93 | for _, g := range groups { |
| 94 | if g.name == "" { |
| 95 | continue |
| 96 | } |
| 97 | if dep := def.GetDependency(g.name); dep != nil { |
| 98 | g.short = dep.Short() |
| 99 | } else if g.name == def.Name { |
| 100 | g.short = def.Short() |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | // Emit groups: core first, then entrypoint modules, then dependencies. |
| 105 | if g, ok := groups[""]; ok { |
| 106 | doc.Add("Available Functions", |
| 107 | nameShortWrapped(g.fns, func(f *modFunction) (string, string) { |
| 108 | return f.CmdName(), f.Short() |
| 109 | }), |
| 110 | ) |
| 111 | } |
| 112 | |
| 113 | // Entrypoint module functions (source module == current module name). |
| 114 | if def.HasModule() { |
| 115 | if g, ok := groups[def.Name]; ok { |
| 116 | title := def.Name |
no test coverage detected