MCPcopy
hub / github.com/dagger/dagger / ModuleDoc

Method ModuleDoc

cmd/dagger/shell_help.go:301–382  ·  view source on GitHub ↗
(m *moduleDef)

Source from the content-addressed store, hash-verified

299}
300
301func (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 )

Callers 1

registerCommandsMethod · 0.95

Calls 15

AddMethod · 0.95
FunctionUseLineMethod · 0.95
AddSectionMethod · 0.95
StringMethod · 0.95
nameShortWrappedFunction · 0.85
RequiredArgsMethod · 0.80
OptionalArgsMethod · 0.80
AsFunctionProviderMethod · 0.80
CmdNameMethod · 0.80
LenMethod · 0.65
StringMethod · 0.65
UsageMethod · 0.65

Tested by

no test coverage detected