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