Skip to main content

Inline Documentation

Dagger modules and Dagger Functions should be documented so that descriptions are shown in the API and the CLI - for example, when calling dagger functions and dagger call ... --help.

The following code snippet shows how to add documentation for:

  • The whole module
  • Function methods
  • Function arguments
// A simple example module to say hello.

// Further documentation for the module here.

package main

import (
"fmt"
"strings"
)

type MyModule struct{}

// Return a greeting.
func (m *MyModule) Hello(
// Who to greet
name string,
// The greeting to display
greeting string,
) string {
return fmt.Sprintf("%s, %s!", greeting, name)
}

// Return a loud greeting.
func (m *MyModule) LoudHello(
// Who to greet
name string,
// The greeting to display
greeting string,
) string {
out := fmt.Sprintf("%s, %s!", greeting, name)
return strings.ToUpper(out)
}

Here is an example of the result from dagger functions:

Name         Description
hello Return a greeting.
loud-hello Return a loud greeting.

Here is an example of the result from dagger call hello --help:

Return a greeting.

USAGE
dagger call hello [arguments]

ARGUMENTS
--greeting string The greeting to display [required]
--name string Who to greet [required]

The following code snippet shows how to add documentation for an object and its fields in your Dagger module:

package main

// The struct represents a single user of the system.
type MyModule struct {
Name string
Age int
}

func New(
// The name of the user.
name string,
// The age of the user.
age int,
) *MyModule {
return &MyModule{
Name: name,
Age: age,
}
}

Here is an example of the result from dagger call --help:

ARGUMENTS
--age string The age of the user. [required]
--name string The name of the user. [required]