sigs.k8s.io/kubebuilder/v3@v3.14.0/pkg/plugins/golang/v2/edit.go (about) 1 /* 2 Copyright 2020 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 //go:deprecated This package has been deprecated 18 package v2 19 20 import ( 21 "fmt" 22 23 "github.com/spf13/pflag" 24 25 "sigs.k8s.io/kubebuilder/v3/pkg/config" 26 "sigs.k8s.io/kubebuilder/v3/pkg/machinery" 27 "sigs.k8s.io/kubebuilder/v3/pkg/plugin" 28 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/golang/v2/scaffolds" 29 ) 30 31 var _ plugin.EditSubcommand = &editSubcommand{} 32 33 type editSubcommand struct { 34 config config.Config 35 36 multigroup bool 37 } 38 39 func (p *editSubcommand) UpdateMetadata(cliMeta plugin.CLIMetadata, subcmdMeta *plugin.SubcommandMetadata) { 40 subcmdMeta.Description = `This command will edit the project configuration. 41 Features supported: 42 - Toggle between single or multi group projects. 43 ` 44 subcmdMeta.Examples = fmt.Sprintf(` # Enable the multigroup layout 45 %[1]s edit --multigroup 46 47 # Disable the multigroup layout 48 %[1]s edit --multigroup=false 49 `, cliMeta.CommandName) 50 } 51 52 func (p *editSubcommand) BindFlags(fs *pflag.FlagSet) { 53 fs.BoolVar(&p.multigroup, "multigroup", false, "enable or disable multigroup layout") 54 } 55 56 func (p *editSubcommand) InjectConfig(c config.Config) error { 57 p.config = c 58 59 return nil 60 } 61 62 func (p *editSubcommand) Scaffold(fs machinery.Filesystem) error { 63 scaffolder := scaffolds.NewEditScaffolder(p.config, p.multigroup) 64 scaffolder.InjectFS(fs) 65 return scaffolder.Scaffold() 66 }