From 7b28c2b97c8d3d7611c18b4134e6623422231dcd Mon Sep 17 00:00:00 2001 From: Jonathan Amsterdam Date: Tue, 25 Jun 2024 17:40:07 -0400 Subject: [PATCH] [Go] use a Makefile to generate doc-go files (#479) --- docs-go/Makefile | 10 ++++++++++ docs-go/{flows => flows.src} | 0 docs-go/{models => models.src} | 0 go/internal/cmd/weave/weave.go | 1 + go/internal/doc-snippets/doc.go | 19 +++++++++++++++++++ 5 files changed, 30 insertions(+) create mode 100644 docs-go/Makefile rename docs-go/{flows => flows.src} (100%) rename docs-go/{models => models.src} (100%) create mode 100644 go/internal/doc-snippets/doc.go diff --git a/docs-go/Makefile b/docs-go/Makefile new file mode 100644 index 000000000..ac1ffd012 --- /dev/null +++ b/docs-go/Makefile @@ -0,0 +1,10 @@ +WEAVE=$(HOME)/go/bin/weave + +all: $(WEAVE) flows.md models.md + +$(WEAVE): ../go/internal/cmd/weave/*.go + go -C ../go install ./internal/cmd/weave + +%.md: %.src + $(WEAVE) $< > $@ + diff --git a/docs-go/flows b/docs-go/flows.src similarity index 100% rename from docs-go/flows rename to docs-go/flows.src diff --git a/docs-go/models b/docs-go/models.src similarity index 100% rename from docs-go/models rename to docs-go/models.src diff --git a/go/internal/cmd/weave/weave.go b/go/internal/cmd/weave/weave.go index 71a1cc72b..9f69560e2 100644 --- a/go/internal/cmd/weave/weave.go +++ b/go/internal/cmd/weave/weave.go @@ -219,6 +219,7 @@ func cleanListing(text, indent string) string { return strings.Join(lines, "\n") } +// leadingTabs counts the number of tabs that start s. func leadingTabs(s string) int { var i int for i = 0; i < len(s); i++ { diff --git a/go/internal/doc-snippets/doc.go b/go/internal/doc-snippets/doc.go new file mode 100644 index 000000000..9e9f9d1b9 --- /dev/null +++ b/go/internal/doc-snippets/doc.go @@ -0,0 +1,19 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package snippets contains snippets that are incorporated into +// documentation (see the docs-go directory under the repo root). +package snippets + +//go:generate make -C ../../../docs-go