sigs.k8s.io/kubebuilder/v3@v3.14.0/pkg/plugins/optional/grafana/v1alpha/init.go (about) 1 /* 2 Copyright 2022 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 package v1alpha 18 19 import ( 20 "fmt" 21 22 "sigs.k8s.io/kubebuilder/v3/pkg/config" 23 "sigs.k8s.io/kubebuilder/v3/pkg/machinery" 24 "sigs.k8s.io/kubebuilder/v3/pkg/plugin" 25 "sigs.k8s.io/kubebuilder/v3/pkg/plugins/optional/grafana/v1alpha/scaffolds" 26 ) 27 28 var _ plugin.InitSubcommand = &initSubcommand{} 29 30 type initSubcommand struct { 31 config config.Config 32 } 33 34 func (p *initSubcommand) UpdateMetadata(cliMeta plugin.CLIMetadata, subcmdMeta *plugin.SubcommandMetadata) { 35 subcmdMeta.Description = MetaDataDescription 36 37 subcmdMeta.Examples = fmt.Sprintf(` # Initialize a common project with this plugin 38 %[1]s init --plugins=grafana.kubebuilder.io/v1-alpha 39 `, cliMeta.CommandName) 40 } 41 42 func (p *initSubcommand) InjectConfig(c config.Config) error { 43 p.config = c 44 return nil 45 } 46 47 func (p *initSubcommand) Scaffold(fs machinery.Filesystem) error { 48 if err := InsertPluginMetaToConfig(p.config, pluginConfig{}); err != nil { 49 return err 50 } 51 52 scaffolder := scaffolds.NewInitScaffolder() 53 scaffolder.InjectFS(fs) 54 return scaffolder.Scaffold() 55 }