Skip to content

Commit

Permalink
cmd/doc: add support for generating package index
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Alba <sam.alba@gmail.com>
  • Loading branch information
samalba committed Jun 23, 2021
1 parent b1d5225 commit 6ff2fed
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/dagger/cmd/doc.go
Expand Up @@ -365,6 +365,14 @@ func walkStdlib(ctx context.Context, output, format string) {
return false
}

// Create main index
index, err := os.Create(path.Join(output, "README.md"))
if err != nil {
lg.Fatal().Err(err).Msg("cannot generate stdlib doc index")
}
defer index.Close()
fmt.Fprintf(index, "# Index\n\n")

for p, pkg := range packages {
filename := fmt.Sprintf("%s.%s", p, format)
// If this package has sub-packages (e.g. `aws`), create
Expand All @@ -384,6 +392,8 @@ func walkStdlib(ctx context.Context, output, format string) {
}
defer f.Close()

// FIXME: sort packages by name
fmt.Fprintf(index, "- [%s](./%s)\n", p, filename)
fmt.Fprintf(f, "%s", pkg.Format(format))
}
}

0 comments on commit 6ff2fed

Please sign in to comment.