Skip to content

Commit 0281d6a

Browse files
committed
BUILD/MINOR: docs: move generation tool to cmd folder
1 parent 8965f76 commit 0281d6a

File tree

14 files changed

+224
-44
lines changed

14 files changed

+224
-44
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ tidy:
2828

2929
.PHONY: doc
3030
doc:
31-
cd documentation/gen/; go run .
31+
cd cmd/docs; go run .
3232

3333
.PHONY: lint
3434
lint:
File renamed without changes.

documentation/gen/annotations.go renamed to cmd/docs/annotations.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2019 HAProxy Technologies 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+
// http://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+
115
package main
216

317
import (
@@ -7,6 +21,8 @@ import (
721
"strings"
822

923
"github.com/google/renameio"
24+
"golang.org/x/text/cases"
25+
"golang.org/x/text/language"
1026
)
1127

1228
var header = `
@@ -133,11 +149,13 @@ func (c *Conf) generateReadmeAnnotations() {
133149
sortedGroups = append(sortedGroups, group)
134150
}
135151
sort.Strings(sortedGroups)
152+
caser := cases.Title(language.Und)
136153
for _, group := range sortedGroups {
137-
buff.WriteString(fmt.Sprintf("#### %s\n\n", strings.ReplaceAll(strings.Title(group), "-", " ")))
154+
buff.WriteString(fmt.Sprintf("#### %s\n\n", strings.ReplaceAll(caser.String(group), "-", " ")))
138155
groupData, haveGroupData := c.Groups[group]
139156
if haveGroupData && groupData.Header != "" {
140-
buff.WriteString(fmt.Sprintf("%s\n\n", groupData.Header))
157+
buff.WriteString(groupData.Header)
158+
buff.WriteString("\n\n")
141159
}
142160
for _, ann := range c.Items {
143161
if ann.Group != group {
@@ -166,14 +184,15 @@ func (c *Conf) generateReadmeAnnotations() {
166184
selectExamples(ann, &buff)
167185
}
168186
if haveGroupData && groupData.Footer != "" {
169-
buff.WriteString(fmt.Sprintf("%s\n\n", groupData.Footer))
187+
buff.WriteString(groupData.Footer)
188+
buff.WriteString("\n\n")
170189
}
171190
buff.WriteString("<p align='right'><a href='#available-annotations'>:arrow_up_small: back to top</a></p>\n\n***\n\n")
172191
}
173192

174193
buff.WriteString(docFooter)
175194

176-
err := renameio.WriteFile("../annotations.md", []byte(buff.String()), 0o644)
195+
err := renameio.WriteFile("../../documentation/annotations.md", []byte(buff.String()), 0o644)
177196
if err != nil {
178197
log.Println(err)
179198
}

documentation/gen/controller.go renamed to cmd/docs/controller.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2019 HAProxy Technologies 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+
// http://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+
115
package main
216

317
import (
@@ -75,7 +89,7 @@ func (c *Conf) generateReadmeController() {
7589
buff.WriteString("<p align='right'><a href='#haproxy-kubernetes-ingress-controller'>:arrow_up_small: back to top</a></p>\n\n***\n\n")
7690
}
7791

78-
err := renameio.WriteFile("../controller.md", []byte(buff.String()), 0o644)
92+
err := renameio.WriteFile("../../documentation/controller.md", []byte(buff.String()), 0o644)
7993
if err != nil {
8094
log.Println(err)
8195
}

documentation/gen/lifecycle.go renamed to cmd/docs/lifecycle.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2019 HAProxy Technologies 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+
// http://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+
115
package main
216

317
import (
@@ -49,7 +63,7 @@ func (c *Conf) generateSupport() {
4963
buff.WriteString(`This is autogenerated from [lifecycle.yaml](lifecycle.yaml). Description can be found in [generator readme](gen/README.md)`)
5064
buff.WriteByte('\n')
5165

52-
err := renameio.WriteFile("../lifecycle.md", []byte(buff.String()), 0o644)
66+
err := renameio.WriteFile("../../documentation/lifecycle.md", []byte(buff.String()), 0o644)
5367
if err != nil {
5468
log.Println(err)
5569
}

cmd/docs/main.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2019 HAProxy Technologies 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+
// http://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+
func main() {
18+
var cn Conf
19+
cn.getConf()
20+
21+
cn.generateReadme()
22+
cn.generateReadmeAnnotations()
23+
cn.generateReadmeController()
24+
cn.generateSupport()
25+
// cn.saveConf()
26+
// cn.saveDocConf()
27+
}

documentation/gen/readme.go renamed to cmd/docs/readme.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,20 @@
1+
// Copyright 2019 HAProxy Technologies 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+
// http://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+
115
package main
216

317
import (
4-
"fmt"
518
"log"
619
"strings"
720

@@ -42,7 +55,7 @@ func (c *Conf) generateReadme() {
4255
buff.WriteString(c.ActiveVersion.String())
4356
buff.WriteString(headerREADME)
4457

45-
err := renameio.WriteFile("../README.md", []byte(buff.String()), 0o644)
58+
err := renameio.WriteFile("../../documentation/README.md", []byte(buff.String()), 0o644)
4659
if err != nil {
4760
log.Println(err)
4861
}
@@ -82,7 +95,6 @@ func selectExamples(ann *ConfItem, buff *strings.Builder) {
8295
buff.WriteString("\n")
8396
}
8497
buff.WriteString("\n```\n\n")
85-
8698
}
8799
return
88100
}
@@ -114,5 +126,5 @@ func writeValue(value, defaultValue string) string {
114126
if value != defaultValue {
115127
return value
116128
}
117-
return fmt.Sprintf("%s `default`", value)
129+
return value + " `default`"
118130
}

documentation/gen/types.go renamed to cmd/docs/types.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright 2019 HAProxy Technologies 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+
// http://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+
115
package main
216

317
import (
@@ -54,16 +68,16 @@ type Conf struct {
5468
}
5569

5670
func (c *Conf) getConf() *Conf {
57-
yamlFile, err := os.ReadFile("../doc.yaml")
71+
yamlFile, err := os.ReadFile("../../documentation/doc.yaml")
5872
if err != nil {
5973
log.Printf("yamlFile.Get err #%v ", err)
6074
}
61-
err = yaml.Unmarshal(yamlFile, c)
75+
err = yaml.Unmarshal(yamlFile, c) //nolint:musttag
6276
if err != nil {
6377
log.Fatalf("Unmarshal: %v", err)
6478
}
6579

66-
yamlFile, err = os.ReadFile("../lifecycle.yaml")
80+
yamlFile, err = os.ReadFile("../../documentation/lifecycle.yaml")
6781
if err != nil {
6882
log.Printf("yamlFile.Get err #%v ", err)
6983
}

documentation/gen/version.go renamed to cmd/docs/version.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1+
// Copyright 2019 HAProxy Technologies 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+
// http://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+
115
package main
216

317
import (
18+
"errors"
419
"fmt"
520
"strconv"
621
"strings"
@@ -21,7 +36,7 @@ func (v *Version) UnmarshalYAML(unmarshal func(interface{}) error) error {
2136

2237
parts := strings.Split(data, ".")
2338
if len(parts) != 2 {
24-
return fmt.Errorf("version is not in correct format")
39+
return errors.New("version is not in correct format")
2540
}
2641
v.Major, err = strconv.Atoi(parts[0])
2742
if err != nil {
@@ -51,6 +66,6 @@ func (v *Version) LowerOrEqual(active Version) bool {
5166
return true
5267
}
5368

54-
func (v Version) MarshalYAML() (interface{}, error) {
69+
func (v Version) MarshalYAML() (interface{}, error) { //nolint:unparam
5570
return v.String(), nil
5671
}

documentation/gen/go.mod

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

0 commit comments

Comments
 (0)