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.

Module documentation

The following code snippet shows how to add high-level module documentation:

// This module returns information about the OS for a container image
package main

// Further documentation for the module here.

import (
"context"
)

type MyModule struct{}

func (*MyModule) Version(ctx context.Context) (string, error) {
return dag.Container().
From("alpine:3.14.0").
WithExec([]string{"/bin/sh", "-c", "cat /etc/os-release | grep VERSION_ID"}).
Stdout(ctx)
}

Function documentation

The following code snippet shows how to add documentation for a function in your Dagger Module:

package main

type MyModule struct{}

// Compute the sum of two numbers.
//
// Example usage: dagger call add --a=4 --b=5
func (*MyModule) Add(
// The first number to add
// +default=4
a int,
// The second number to add
b int,
) int {
return a + b
}

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

Compute the sum of two numbers.

Example usage: dagger call add --a=4 --b=5

Usage:
dagger call add [flags]

EXPERIMENTAL:
dagger call add is currently under development and may change in the future.

Flags:
--a int The first number to add (default 4)
--b int The second number to add

Object and field documentation

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

package main

// The Person struct represents a single user of the system
type Person struct {
// The name of the person.
Name string
// The age of the person.
Age int
}

func New(name string, age int) *Person {
return &Person{
Name: name,
Age: age,
}
}

Here is an example of the result from dagger functions:

Name   Description
age The age of the person.
name The name of the person.