From b03e695970902273c15804fefc2aa6f2603c01cf Mon Sep 17 00:00:00 2001 From: Sam Alba Date: Wed, 23 Jun 2021 10:49:19 +0200 Subject: [PATCH] docs: stdlib index sorted alphabetically Signed-off-by: Sam Alba --- cmd/dagger/cmd/doc.go | 29 +++++++++++++++------- docs/reference/universe/README.md | 40 +++++++++++++++---------------- 2 files changed, 41 insertions(+), 28 deletions(-) diff --git a/cmd/dagger/cmd/doc.go b/cmd/dagger/cmd/doc.go index 453ecb9b..0e91fc6e 100644 --- a/cmd/dagger/cmd/doc.go +++ b/cmd/dagger/cmd/doc.go @@ -8,6 +8,7 @@ import ( "os" "path" "path/filepath" + "sort" "strings" "text/tabwriter" "unicode/utf8" @@ -365,6 +366,17 @@ func walkStdlib(ctx context.Context, output, format string) { return false } + // get filename from a package name + getFileName := func(p string) string { + filename := fmt.Sprintf("%s.%s", p, format) + // If this package has sub-packages (e.g. `aws`), create + // `aws/README.md` instead of `aws.md`. + if hasSubPackages(p) { + filename = fmt.Sprintf("%s/README.%s", p, format) + } + return filename + } + // Create main index index, err := os.Create(path.Join(output, "README.md")) if err != nil { @@ -372,14 +384,10 @@ func walkStdlib(ctx context.Context, output, format string) { } defer index.Close() fmt.Fprintf(index, "# Index\n\n") + indexKeys := []string{} for p, pkg := range packages { - filename := fmt.Sprintf("%s.%s", p, format) - // If this package has sub-packages (e.g. `aws`), create - // `aws/README.md` instead of `aws.md`. - if hasSubPackages(p) { - filename = fmt.Sprintf("%s/README.%s", p, format) - } + filename := getFileName(p) filepath := path.Join(output, filename) if err := os.MkdirAll(path.Dir(filepath), 0755); err != nil { @@ -392,8 +400,13 @@ func walkStdlib(ctx context.Context, output, format string) { } defer f.Close() - // FIXME: sort packages by name - fmt.Fprintf(index, "- [%s](./%s)\n", p, filename) + indexKeys = append(indexKeys, p) fmt.Fprintf(f, "%s", pkg.Format(format)) } + + // Generate index from sorted list of packages + sort.Strings(indexKeys) + for _, p := range indexKeys { + fmt.Fprintf(index, "- [%s](./%s)\n", p, getFileName(p)) + } } diff --git a/docs/reference/universe/README.md b/docs/reference/universe/README.md index 97837fff..3ce061f4 100644 --- a/docs/reference/universe/README.md +++ b/docs/reference/universe/README.md @@ -1,28 +1,28 @@ # Index -- [aws](./aws/README.md) -- [aws/ecr](./aws/ecr.md) -- [aws/rds](./aws/rds.md) -- [git](./git.md) -- [kubernetes](./kubernetes/README.md) -- [terraform](./terraform.md) -- [random](./random.md) -- [aws/ecs](./aws/ecs.md) -- [aws/s3](./aws/s3.md) -- [dagger/op](./dagger/op.md) -- [gcp](./gcp/README.md) -- [go](./go.md) -- [js/yarn](./js/yarn.md) -- [kubernetes/helm](./kubernetes/helm.md) -- [docker](./docker.md) -- [gcp/gcr](./gcp/gcr.md) -- [gcp/gke](./gcp/gke.md) -- [io](./io.md) -- [kubernetes/kustomize](./kubernetes/kustomize.md) -- [os](./os.md) - [alpine](./alpine.md) +- [aws](./aws/README.md) - [aws/cloudformation](./aws/cloudformation.md) +- [aws/ecr](./aws/ecr.md) +- [aws/ecs](./aws/ecs.md) - [aws/eks](./aws/eks.md) - [aws/elb](./aws/elb.md) +- [aws/rds](./aws/rds.md) +- [aws/s3](./aws/s3.md) - [dagger](./dagger/README.md) +- [dagger/op](./dagger/op.md) +- [docker](./docker.md) +- [gcp](./gcp/README.md) +- [gcp/gcr](./gcp/gcr.md) +- [gcp/gke](./gcp/gke.md) +- [git](./git.md) +- [go](./go.md) +- [io](./io.md) +- [js/yarn](./js/yarn.md) +- [kubernetes](./kubernetes/README.md) +- [kubernetes/helm](./kubernetes/helm.md) +- [kubernetes/kustomize](./kubernetes/kustomize.md) - [netlify](./netlify.md) +- [os](./os.md) +- [random](./random.md) +- [terraform](./terraform.md)