• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

operator-framework / operator-sdk / 19850202700

02 Dec 2025 07:05AM UTC coverage: 31.383%. First build
19850202700

Pull #7029

github

PascalBourdier
acornett21 review
Pull Request #7029: ci: use golangci-lint v2

4 of 52 new or added lines in 20 files covered. (7.69%)

4377 of 13947 relevant lines covered (31.38%)

13.43 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/hack/generate/cli-doc/gen-cli-doc.go
1
// Copyright 2019 The Operator-SDK Authors
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
import (
18
        "fmt"
19
        "os"
20
        "path"
21
        "path/filepath"
22
        "strings"
23

24
        log "github.com/sirupsen/logrus"
25
        "github.com/spf13/cobra"
26
        "github.com/spf13/cobra/doc"
27

28
        "github.com/operator-framework/operator-sdk/internal/cmd/operator-sdk/cli"
29
)
30

31
const fmTemplate = `---
32
title: "%s"
33
---
34
`
35

36
func main() {
×
37
        currentDir, err := os.Getwd()
×
38
        if err != nil {
×
39
                log.Fatalf("Failed to get current directory: %v", err)
×
40
        }
×
41

42
        cliDocsPath := filepath.Join(currentDir, "website", "content", "en", "docs", "cli")
×
43
        _, cliRoot := cli.GetPluginsCLIAndRoot()
×
44
        cliRoot.DisableAutoGenTag = true
×
45
        recreateDocDir(cliRoot, cliDocsPath)
×
46
}
47

48
// htmlFormatter will replace angular brackets (`<` and `>`) with its character entitites
49
// `&lt;` and `&gt;`
50
func htmlFormatter(rootCmd *cobra.Command) {
×
51

×
52
        for _, cmds := range rootCmd.Commands() {
×
53
                if len(cmds.Commands()) > 0 {
×
54
                        htmlFormatter(cmds)
×
55
                }
×
56

57
                cmds.Long = strings.ReplaceAll(cmds.Long, "<", "&lt;")
×
58
                cmds.Long = strings.ReplaceAll(cmds.Long, ">", "&gt;")
×
59
        }
60

61
}
62

63
// recreateDocDir removes and recreates the CLI doc directory for rootCmd
64
// at docPath to ensure that stale files (e.g. from renamed or removed CLI subcommands)
65
// are removed.
66
func recreateDocDir(rootCmd *cobra.Command, docPath string) {
×
67
        currentDir, err := os.Getwd()
×
68
        if err != nil {
×
69
                log.Fatalf("Failed to get current directory: %v", err)
×
70
        }
×
71

72
        if err := os.Rename(docPath+"/_index.md", currentDir+"/tmp_index.md"); err != nil {
×
73
                log.Fatalf("Failed to move existing index: %v", err)
×
74
        }
×
75
        if err := os.RemoveAll(docPath); err != nil {
×
76
                log.Fatalf("Failed to remove existing generated docs: %v", err)
×
77
        }
×
78
        if err := os.MkdirAll(docPath, 0755); err != nil {
×
79
                log.Fatalf("Failed to re-create docs directory: %v", err)
×
80
        }
×
81

82
        filePrepender := func(filename string) string {
×
83
                name := filepath.Base(filename)
×
84
                base := strings.TrimSuffix(name, path.Ext(name))
×
NEW
85
                return fmt.Sprintf(fmTemplate, strings.ReplaceAll(base, "_", " "))
×
86
        }
×
87
        linkHandler := func(name string) string {
×
88
                base := strings.TrimSuffix(name, path.Ext(name))
×
89
                return "../" + base
×
90
        }
×
91

92
        htmlFormatter(rootCmd)
×
93

×
94
        err = doc.GenMarkdownTreeCustom(rootCmd, docPath, filePrepender, linkHandler)
×
95
        if err != nil {
×
96
                log.Fatalf("Failed to generate documentation: %v", err)
×
97
        }
×
98

99
        if err := os.Rename(currentDir+"/tmp_index.md", docPath+"/_index.md"); err != nil {
×
100
                log.Fatalf("Failed to move existing index: %v", err)
×
101
        }
×
102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc