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

kubernetes-sigs / kubebuilder / 14056759001

25 Mar 2025 09:54AM UTC coverage: 72.977% (-0.009%) from 72.986%
14056759001

Pull #4643

github

kersten
fix: avoid variable shadowing by renaming local 'errors' variable

The local variable 'errors' was shadowing the standard library 'errors' package,
which can lead to confusion and potential issues when calling package functions.
Renamed the variable to 'errs' to clarify intent and resolve the name collision.
Pull Request #4643: 🌱 (chore): avoid variable shadowing by renaming local 'errors' variable

3 of 3 new or added lines in 1 file covered. (100.0%)

2309 of 3164 relevant lines covered (72.98%)

13.98 hits per line

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

76.92
/pkg/cli/alpha/command.go
1
/*
2
Copyright 2023 The Kubernetes Authors.
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
        http://www.apache.org/licenses/LICENSE-2.0
7
Unless required by applicable law or agreed to in writing, software
8
distributed under the License is distributed on an "AS IS" BASIS,
9
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
See the License for the specific language governing permissions and
11
limitations under the License.
12
*/
13

14
package alpha
15

16
import (
17
        log "github.com/sirupsen/logrus"
18
        "github.com/spf13/cobra"
19
        "sigs.k8s.io/kubebuilder/v4/pkg/cli/alpha/internal"
20
)
21

22
// NewScaffoldCommand returns a new scaffold command, providing the `kubebuilder alpha generate`
23
// feature to re-scaffold projects and assist users with updates.
24
//
25
// IMPORTANT: This command is intended solely for Kubebuilder's use, as it is designed to work
26
// specifically within Kubebuilder's project configuration, key mappings, and plugin initialization.
27
// Its implementation includes fixed values and logic tailored to Kubebuilder’s unique setup, which may
28
// not apply to other projects. Consequently, importing and using this command directly in other projects
29
// will likely result in unexpected behavior, as external projects may have different supported plugin
30
// structures, configurations, and requirements.
31
//
32
// For other projects using Kubebuilder as a library, replicating similar functionality would require
33
// a custom implementation to ensure compatibility with the specific configurations and plugins of that project.
34
//
35
// Technically, implementing functions that allow re-scaffolding with the exact plugins and project-specific
36
// code of external projects is not feasible within Kubebuilder’s current design.
37
func NewScaffoldCommand() *cobra.Command {
1✔
38
        opts := internal.Generate{}
1✔
39
        scaffoldCmd := &cobra.Command{
1✔
40
                Use:   "generate",
1✔
41
                Short: "Re-scaffold an existing Kuberbuilder project",
1✔
42
                Long: `It's an experimental feature that has the purpose of re-scaffolding the whole project from the scratch 
1✔
43
using the current version of KubeBuilder binary available.
1✔
44
# make sure the PROJECT file is in the 'input-dir' argument, the default is the current directory.
1✔
45
$ kubebuilder alpha generate --input-dir="./test" --output-dir="./my-output"
1✔
46
Then we will re-scaffold the project by Kubebuilder in the directory specified by 'output-dir'.
1✔
47
                `,
1✔
48
                PreRunE: func(_ *cobra.Command, _ []string) error {
1✔
49
                        return opts.Validate()
×
50
                },
×
51
                Run: func(_ *cobra.Command, _ []string) {
×
52
                        if err := opts.Generate(); err != nil {
×
53
                                log.Fatalf("Failed to command %s", err)
×
54
                        }
×
55
                },
56
        }
57
        scaffoldCmd.Flags().StringVar(&opts.InputDir, "input-dir", "",
1✔
58
                "Specifies the full path to a Kubebuilder project file. If not provided, "+
1✔
59
                        "the current working directory is used.")
1✔
60
        scaffoldCmd.Flags().StringVar(&opts.OutputDir, "output-dir", "",
1✔
61
                "Specifies the full path where the scaffolded files will be output. "+
1✔
62
                        "Defaults to a directory within the current working directory.")
1✔
63

1✔
64
        return scaffoldCmd
1✔
65
}
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