sigs.k8s.io/kubebuilder/v3@v3.14.0/pkg/plugins/external/api.go (about) 1 /* 2 Copyright 2021 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 external 18 19 import ( 20 "github.com/spf13/pflag" 21 22 "sigs.k8s.io/kubebuilder/v3/pkg/machinery" 23 "sigs.k8s.io/kubebuilder/v3/pkg/model/resource" 24 "sigs.k8s.io/kubebuilder/v3/pkg/plugin" 25 "sigs.k8s.io/kubebuilder/v3/pkg/plugin/external" 26 ) 27 28 var _ plugin.CreateAPISubcommand = &createAPISubcommand{} 29 30 const ( 31 defaultAPIVersion = "v1alpha1" 32 ) 33 34 type createAPISubcommand struct { 35 Path string 36 Args []string 37 } 38 39 func (p *createAPISubcommand) InjectResource(*resource.Resource) error { 40 // Do nothing since resource flags are passed to the external plugin directly. 41 return nil 42 } 43 44 func (p *createAPISubcommand) UpdateMetadata(_ plugin.CLIMetadata, subcmdMeta *plugin.SubcommandMetadata) { 45 setExternalPluginMetadata("api", p.Path, subcmdMeta) 46 } 47 48 func (p *createAPISubcommand) BindFlags(fs *pflag.FlagSet) { 49 bindExternalPluginFlags(fs, "api", p.Path, p.Args) 50 } 51 52 func (p *createAPISubcommand) Scaffold(fs machinery.Filesystem) error { 53 req := external.PluginRequest{ 54 APIVersion: defaultAPIVersion, 55 Command: "create api", 56 Args: p.Args, 57 } 58 59 err := handlePluginResponse(fs, req, p.Path) 60 if err != nil { 61 return err 62 } 63 64 return nil 65 }