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

kubernetes-sigs / kubebuilder / 15793548358

21 Jun 2025 07:38AM UTC coverage: 71.385% (+0.1%) from 71.281%
15793548358

push

github

web-flow
Merge pull request #4846 from camilamacedo86/fix-help-info-alpha

✨ (cli): enhance help information for kubebuilder alpha generate command

23 of 24 new or added lines in 1 file covered. (95.83%)

2355 of 3299 relevant lines covered (71.39%)

16.44 hits per line

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

84.21
/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

1✔
40
        scaffoldCmd := &cobra.Command{
1✔
41
                Use:   "generate",
1✔
42
                Short: "Re-scaffold a Kubebuilder project from its PROJECT file",
1✔
43
                Long: `The 'generate' command re-creates a Kubebuilder project scaffold based on the configuration 
1✔
44
defined in the PROJECT file, using the latest installed Kubebuilder version and plugins.
1✔
45

1✔
46
This is helpful for migrating projects to a newer Kubebuilder layout or plugin version (e.g., v3 to v4)
1✔
47
as update your project from any previous version to the current one.
1✔
48

1✔
49
If no output directory is provided, the current working directory will be cleaned (except .git and PROJECT).`,
1✔
50
                Example: `
1✔
51
  # **WARNING**(will delete all files to allow the re-scaffold except .git and PROJECT)
1✔
52
  # Re-scaffold the project in-place 
1✔
53
  kubebuilder alpha generate
1✔
54

1✔
55
  # Re-scaffold the project from ./test into ./my-output
1✔
56
  kubebuilder alpha generate --input-dir="./path/to/project" --output-dir="./my-output"
1✔
57
`,
1✔
58
                PreRunE: func(_ *cobra.Command, _ []string) error {
1✔
59
                        return opts.Validate()
×
60
                },
×
61
                Run: func(_ *cobra.Command, _ []string) {
×
62
                        if err := opts.Generate(); err != nil {
×
NEW
63
                                log.Fatalf("failed to generate project: %s", err)
×
64
                        }
×
65
                },
66
        }
67

68
        scaffoldCmd.Flags().StringVar(&opts.InputDir, "input-dir", "",
1✔
69
                "Path to the directory containing the PROJECT file. "+
1✔
70
                        "Defaults to the current working directory. WARNING: delete existing files (except .git and PROJECT).")
1✔
71

1✔
72
        scaffoldCmd.Flags().StringVar(&opts.OutputDir, "output-dir", "",
1✔
73
                "Directory where the new project scaffold will be written. "+
1✔
74
                        "If unset, re-scaffolding occurs in-place "+
1✔
75
                        "and will delete existing files (except .git and PROJECT).")
1✔
76

1✔
77
        return scaffoldCmd
1✔
78
}
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

© 2025 Coveralls, Inc