Skip to content

Commit fa24925

Browse files
authored
chore: add doc.go in cmd/automation (#2810)
Add an empty doc.go in `cmd/automation`. In addition, modify `doc_generate.go` so that it can be used to generate docs for different packages. For #2416
1 parent fb8c557 commit fa24925

File tree

6 files changed

+99
-48
lines changed

6 files changed

+99
-48
lines changed

cmd/automation/doc.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
//go:generate go run -tags docgen ../doc_generate.go -cmd .
16+
17+
/*
18+
Librarian manages Google API client libraries by automating onboarding,
19+
regeneration, and release. It runs language-agnostic workflows while
20+
delegating language-specific tasks—such as code generation, building, and
21+
testing—to Docker images.
22+
23+
Usage:
24+
25+
librarian <command> [arguments]
26+
27+
The commands are:
28+
*/
29+
package main

cmd/automation/main.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// Librarian manages Google API client libraries by automating onboarding,
16-
// regeneration, and release. It runs language‑agnostic workflows while
17-
// delegating language‑specific tasks—such as code generation, building, and
18-
// testing—to Docker images.
1915
package main
2016

2117
import (

cmd/librarian/doc_generate.go renamed to cmd/doc_generate.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package main
1919
import (
2020
"bytes"
2121
"errors"
22+
"flag"
2223
"fmt"
2324
"log"
2425
"os"
@@ -41,7 +42,7 @@ const docTemplate = `// Copyright 2025 Google LLC
4142
// See the License for the specific language governing permissions and
4243
// limitations under the License.
4344
44-
//go:generate go run -tags docgen doc_generate.go
45+
//go:generate go run -tags docgen ../doc_generate.go -cmd .
4546
4647
/*
4748
Librarian manages Google API client libraries by automating onboarding,
@@ -76,7 +77,13 @@ type CommandDoc struct {
7677
Commands []CommandDoc
7778
}
7879

80+
var cmdPath = flag.String("cmd", "", "Path to the command to generate docs for (e.g., ../../cmd/librarian)")
81+
7982
func main() {
83+
flag.Parse()
84+
if *cmdPath == "" {
85+
log.Fatal("must specify -cmd flag")
86+
}
8087
if err := run(); err != nil {
8188
log.Fatal(err)
8289
}
@@ -164,7 +171,7 @@ func buildCommandDocs(parentCommand string) ([]CommandDoc, error) {
164171

165172
func getCommandHelpText(command string) (string, error) {
166173
parts := strings.Fields(command)
167-
args := []string{"run", "../../cmd/librarian/"}
174+
args := []string{"run", *cmdPath}
168175
args = append(args, parts...)
169176
args = append(args, "--help")
170177
cmd := exec.Command("go", args...)

cmd/doc_generate_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"bytes"
19+
"os/exec"
20+
"testing"
21+
)
22+
23+
func TestGoGenerateLibrarianDoc(t *testing.T) {
24+
for _, test := range []struct {
25+
name string
26+
docFile string
27+
}{
28+
{
29+
name: "automation_doc",
30+
docFile: "cmd/automation/doc.go",
31+
},
32+
{
33+
name: "librarian_doc",
34+
docFile: "cmd/librarian/doc.go",
35+
},
36+
} {
37+
t.Run(test.name, func(t *testing.T) {
38+
t.Parallel()
39+
cmd := exec.Command("go", "generate", "./...")
40+
var stderr, stdout bytes.Buffer
41+
cmd.Stderr = &stderr
42+
cmd.Stdout = &stdout
43+
t.Log(stderr.String())
44+
t.Log(stdout.String())
45+
if err := cmd.Run(); err != nil {
46+
t.Fatalf("%v: %v", cmd, err)
47+
}
48+
cmd = exec.Command("git", "diff", "--exit-code", "--", test.docFile)
49+
if err := cmd.Run(); err != nil {
50+
t.Errorf("go generate produced a diff, please run `go generate ./...` and commit the changes")
51+
cmd = exec.Command("git", "diff", "--", test.docFile)
52+
out, err := cmd.CombinedOutput()
53+
if err != nil {
54+
t.Fatalf("git diff failed: %v", err)
55+
}
56+
t.Logf("diff:\n%s", out)
57+
}
58+
})
59+
}
60+
}

cmd/librarian/doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
//go:generate go run -tags docgen doc_generate.go
15+
//go:generate go run -tags docgen ../doc_generate.go -cmd .
1616

1717
/*
1818
Librarian manages Google API client libraries by automating onboarding,

cmd/librarian/doc_generate_test.go

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)