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

kubernetes-sigs / kubebuilder / 11291884401

11 Oct 2024 11:57AM UTC coverage: 75.099% (-6.8%) from 81.935%
11291884401

push

github

web-flow
⚠️ cleanup/refactor: Alpha Generate command (#4180)

cleanup/refactor: Alpha Generate command

- Refactored the code implementation to improve error handling, encapsulate logic, and streamline execution flow.
- Moved the code implementation from `pkg` to the CLI since it pertains directly to a command.
- Additionally, moved the implementation to `internal` to prevent exposing the `Generate` code and avoid unintentional extensions on this alpha feature.

1 of 99 new or added lines in 2 files covered. (1.01%)

2286 of 3044 relevant lines covered (75.1%)

14.44 hits per line

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

75.0
/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 return a new scaffold command
23
func NewScaffoldCommand() *cobra.Command {
1✔
24
        opts := internal.Generate{}
1✔
25
        scaffoldCmd := &cobra.Command{
1✔
26
                Use:   "generate",
1✔
27
                Short: "Re-scaffold an existing Kuberbuilder project",
1✔
28
                Long: `It's an experimental feature that has the purpose of re-scaffolding the whole project from the scratch 
1✔
29
using the current version of KubeBuilder binary available.
1✔
30
# make sure the PROJECT file is in the 'input-dir' argument, the default is the current directory.
1✔
31
$ kubebuilder alpha generate --input-dir="./test" --output-dir="./my-output"
1✔
32
Then we will re-scaffold the project by Kubebuilder in the directory specified by 'output-dir'.
1✔
33
                `,
1✔
34
                PreRunE: func(_ *cobra.Command, _ []string) error {
1✔
35
                        return opts.Validate()
×
36
                },
×
37
                Run: func(_ *cobra.Command, _ []string) {
×
NEW
38
                        if err := opts.Generate(); err != nil {
×
NEW
39
                                log.Fatalf("Failed to command %s", err)
×
40
                        }
×
41
                },
42
        }
43
        scaffoldCmd.Flags().StringVar(&opts.InputDir, "input-dir", "",
1✔
44
                "path to a Kubebuilder project file if not in the current working directory")
1✔
45
        scaffoldCmd.Flags().StringVar(&opts.OutputDir, "output-dir", "",
1✔
46
                "path to output the scaffolding. defaults a directory in the current working directory")
1✔
47

1✔
48
        return scaffoldCmd
1✔
49
}
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