From 6ff2fed9601ba73f43e7d6650d3f0f5ce2c5f180 Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Tue, 22 Jun 2021 17:43:46 +0200 Subject: [PATCH] cmd/doc: add support for generating package index Signed-off-by: Sam Alba --- cmd/dagger/cmd/doc.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/dagger/cmd/doc.go b/cmd/dagger/cmd/doc.go index ee8b21ef..453ecb9b 100644 --- a/cmd/dagger/cmd/doc.go +++ b/cmd/dagger/cmd/doc.go @@ -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 @@ -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)) } }