Skip to content

Commit 8b3fd1c

Browse files
committed
Create a new output mode for creating group and version combination
1 parent 7de9892 commit 8b3fd1c

3 files changed

Lines changed: 31 additions & 3 deletions

File tree

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ crd-ref-docs \
4242
```
4343

4444
Default output mode writes all data to a single output file.
45-
You can choose between single mode and group mode by specifying the output mode.
45+
You can choose between single mode, group mode, or version mode by specifying the output mode.
4646
In group mode, separate files are created for each API group, ensuring that the specified output path is an existing directory.
4747
```
4848
crd-ref-docs \
@@ -51,6 +51,14 @@ crd-ref-docs \
5151
--output-path=./docs \
5252
--output-mode=group
5353
```
54+
In version mode, separate files are created for each API group and version combination, ensuring that the specified output path is an existing directory.
55+
```
56+
crd-ref-docs \
57+
--source-path=$GOPATH/src/github.com/elastic/cloud-on-k8s/pkg/apis \
58+
--config=config.yaml \
59+
--output-path=./docs \
60+
--output-mode=version
61+
```
5462

5563
### Configuration
5664

config/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,9 @@ type KnownType struct {
6363
}
6464

6565
const (
66-
OutputModeSingle = "single"
67-
OutputModeGroup = "group"
66+
OutputModeSingle = "single"
67+
OutputModeGroup = "group"
68+
OutputModeGroupVersion = "version"
6869
)
6970

7071
type Flags struct {

renderer/renderer.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"io/fs"
2222
"os"
2323
"path/filepath"
24+
"strings"
2425
"text/template"
2526

2627
"github.com/elastic/crd-ref-docs/config"
@@ -91,6 +92,24 @@ func renderTemplate(tmpl *template.Template, conf *config.Config, fileExtension
9192
return err
9293
}
9394

95+
if err := tmpl.ExecuteTemplate(file, mainTemplate, []types.GroupVersionDetails{gvd}); err != nil {
96+
return err
97+
}
98+
}
99+
case config.OutputModeGroupVersion:
100+
for _, gvd := range gvds {
101+
// To avoid filenames containing filepath separators, replace them with a non-separator value.
102+
// Using the GroupVersionString is the core difference between this output mode and the regular
103+
// group mode.
104+
name := strings.NewReplacer("/", "-").Replace(gvd.GroupVersionString())
105+
106+
fileName := fmt.Sprintf("%s.%s", name, fileExtension)
107+
file, err := createOutFile(conf.OutputPath, true, fileName)
108+
defer file.Close()
109+
if err != nil {
110+
return err
111+
}
112+
94113
if err := tmpl.ExecuteTemplate(file, mainTemplate, []types.GroupVersionDetails{gvd}); err != nil {
95114
return err
96115
}

0 commit comments

Comments
 (0)