Skip to content

Commit 1289914

Browse files
authored
chore: update doc temp (#2838)
Update doc template to correctly generate docs for automation package. For #2416
1 parent 34fe816 commit 1289914

2 files changed

Lines changed: 48 additions & 19 deletions

File tree

cmd/automation/doc.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515
//go:generate go run -tags docgen ../doc_generate.go -cmd .
1616

1717
/*
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.
18+
Automation provides logic to trigger Cloud Build jobs that run Librarian commands for
19+
any repository listed in internal/automation/prod/repositories.yaml.
2220
2321
Usage:
2422
25-
librarian <command> [arguments]
23+
automation <command> [arguments]
2624
2725
The commands are:
2826

cmd/doc_generate.go

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,30 @@ import (
2424
"log"
2525
"os"
2626
"os/exec"
27+
"path/filepath"
2728
"strings"
2829
"text/template"
2930
)
3031

31-
const docTemplate = `// Copyright 2025 Google LLC
32+
const (
33+
librarianDescription = `Librarian manages Google API client libraries by automating onboarding,
34+
regeneration, and release. It runs language-agnostic workflows while
35+
delegating language-specific tasks—such as code generation, building, and
36+
testing—to Docker images.
37+
38+
Usage:
39+
40+
librarian <command> [arguments]
41+
`
42+
automationDescription = `Automation provides logic to trigger Cloud Build jobs that run Librarian commands for
43+
any repository listed in internal/automation/prod/repositories.yaml.
44+
45+
Usage:
46+
47+
automation <command> [arguments]
48+
`
49+
50+
docTemplate = `// Copyright 2025 Google LLC
3251
//
3352
// Licensed under the Apache License, Version 2.0 (the "License");
3453
// you may not use this file except in compliance with the License.
@@ -45,14 +64,7 @@ const docTemplate = `// Copyright 2025 Google LLC
4564
//go:generate go run -tags docgen ../doc_generate.go -cmd .
4665
4766
/*
48-
Librarian manages Google API client libraries by automating onboarding,
49-
regeneration, and release. It runs language-agnostic workflows while
50-
delegating language-specific tasks—such as code generation, building, and
51-
testing—to Docker images.
52-
53-
Usage:
54-
55-
librarian <command> [arguments]
67+
{{.Description}}
5668
5769
The commands are:
5870
{{range .Commands}}{{template "command" .}}{{end}}
@@ -69,6 +81,7 @@ package main
6981
{{end}}
7082
{{end}}
7183
`
84+
)
7285

7386
// CommandDoc holds the documentation for a single CLI command.
7487
type CommandDoc struct {
@@ -84,13 +97,13 @@ func main() {
8497
if *cmdPath == "" {
8598
log.Fatal("must specify -cmd flag")
8699
}
87-
if err := run(); err != nil {
100+
if err := run(cmdPath); err != nil {
88101
log.Fatal(err)
89102
}
90103
}
91104

92-
func run() error {
93-
if err := processFile(); err != nil {
105+
func run(cmdPath *string) error {
106+
if err := processFile(cmdPath); err != nil {
94107
return err
95108
}
96109
cmd := exec.Command("goimports", "-w", "doc.go")
@@ -100,7 +113,7 @@ func run() error {
100113
return nil
101114
}
102115

103-
func processFile() error {
116+
func processFile(cmdPath *string) error {
104117
commands, err := buildCommandDocs("")
105118
if err != nil {
106119
return err
@@ -112,8 +125,26 @@ func processFile() error {
112125
}
113126
defer docFile.Close()
114127

128+
pkgPath, err := filepath.Abs(*cmdPath)
129+
if err != nil {
130+
return fmt.Errorf("could not find path: %v", err)
131+
}
132+
133+
var pkg string
134+
if filepath.Base(pkgPath) == "automation" {
135+
pkg = automationDescription
136+
} else {
137+
pkg = librarianDescription
138+
}
139+
115140
tmpl := template.Must(template.New("doc").Parse(docTemplate))
116-
if err := tmpl.Execute(docFile, struct{ Commands []CommandDoc }{Commands: commands}); err != nil {
141+
if err := tmpl.Execute(docFile, struct {
142+
Description string
143+
Commands []CommandDoc
144+
}{
145+
Description: pkg,
146+
Commands: commands,
147+
}); err != nil {
117148
return fmt.Errorf("could not execute template: %v", err)
118149
}
119150
return nil

0 commit comments

Comments
 (0)