(m *moduleDef)
| 299 | } |
| 300 | |
| 301 | func (h *shellCallHandler) ModuleDoc(m *moduleDef) string { |
| 302 | var doc ShellDoc |
| 303 | |
| 304 | meta := new(strings.Builder) |
| 305 | meta.WriteString(m.Name) |
| 306 | |
| 307 | description := m.Description |
| 308 | if description == "" { |
| 309 | if mainObj := m.GetObject(m.Name); mainObj != nil { |
| 310 | description = mainObj.Description |
| 311 | } |
| 312 | } |
| 313 | if description != "" { |
| 314 | meta.WriteString("\n\n") |
| 315 | meta.WriteString(description) |
| 316 | } |
| 317 | if meta.Len() > 0 { |
| 318 | doc.Add("Module", meta.String()) |
| 319 | } |
| 320 | |
| 321 | // When entrypoint proxying is active, MainObject is Query and the |
| 322 | // constructor is the synthetic `with` function. Look up the module's |
| 323 | // named main object to get the original constructor and its functions. |
| 324 | constr := m.MainObject.AsObject.Constructor |
| 325 | mainObj := m.GetObject(m.Name) |
| 326 | if mainObj != nil && mainObj.Constructor != nil && mainObj.Constructor.Name != "" { |
| 327 | constr = mainObj.Constructor |
| 328 | } |
| 329 | |
| 330 | usage := h.FunctionUseLine(m, constr) |
| 331 | |
| 332 | if len(constr.Args) > 0 { |
| 333 | constructor := new(strings.Builder) |
| 334 | constructor.WriteString("Usage: ") |
| 335 | constructor.WriteString(usage) |
| 336 | |
| 337 | if constr.Description != "" { |
| 338 | constructor.WriteString("\n\n") |
| 339 | constructor.WriteString(constr.Description) |
| 340 | } |
| 341 | |
| 342 | doc.Add("Entrypoint", constructor.String()) |
| 343 | |
| 344 | if args := constr.RequiredArgs(); len(args) > 0 { |
| 345 | doc.AddSection( |
| 346 | "Required Arguments", |
| 347 | nameShortWrapped(args, func(a *modFunctionArg) (string, string) { |
| 348 | return strings.TrimPrefix(a.Usage(), "--"), a.Long() |
| 349 | }), |
| 350 | ) |
| 351 | } |
| 352 | if args := constr.OptionalArgs(); len(args) > 0 { |
| 353 | doc.AddSection( |
| 354 | "Optional Arguments", |
| 355 | nameShortWrapped(args, func(a *modFunctionArg) (string, string) { |
| 356 | return a.Usage(), a.Long() |
| 357 | }), |
| 358 | ) |
no test coverage detected