sigs.k8s.io/kubebuilder/v3@v3.14.0/pkg/plugin/subcommand.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 package plugin 18 19 import ( 20 "github.com/spf13/pflag" 21 22 "sigs.k8s.io/kubebuilder/v3/pkg/config" 23 "sigs.k8s.io/kubebuilder/v3/pkg/machinery" 24 "sigs.k8s.io/kubebuilder/v3/pkg/model/resource" 25 ) 26 27 // UpdatesMetadata is an interface that implements the optional metadata update method. 28 type UpdatesMetadata interface { 29 // UpdateMetadata updates the subcommand metadata. 30 UpdateMetadata(CLIMetadata, *SubcommandMetadata) 31 } 32 33 // HasFlags is an interface that implements the optional bind flags method. 34 type HasFlags interface { 35 // BindFlags binds flags to the CLI subcommand. 36 BindFlags(*pflag.FlagSet) 37 } 38 39 // RequiresConfig is an interface that implements the optional inject config method. 40 type RequiresConfig interface { 41 // InjectConfig injects the configuration to a subcommand. 42 InjectConfig(config.Config) error 43 } 44 45 // RequiresResource is an interface that implements the required inject resource method. 46 type RequiresResource interface { 47 // InjectResource injects the resource model to a subcommand. 48 InjectResource(*resource.Resource) error 49 } 50 51 // HasPreScaffold is an interface that implements the optional pre-scaffold method. 52 type HasPreScaffold interface { 53 // PreScaffold executes tasks before the main scaffolding. 54 PreScaffold(machinery.Filesystem) error 55 } 56 57 // Scaffolder is an interface that implements the required scaffold method. 58 type Scaffolder interface { 59 // Scaffold implements the main scaffolding. 60 Scaffold(machinery.Filesystem) error 61 } 62 63 // HasPostScaffold is an interface that implements the optional post-scaffold method. 64 type HasPostScaffold interface { 65 // PostScaffold executes tasks after the main scaffolding. 66 PostScaffold() error 67 } 68 69 // Subcommand is a base interface for all subcommands. 70 type Subcommand interface { 71 Scaffolder 72 } 73 74 // InitSubcommand is an interface that represents an `init` subcommand. 75 type InitSubcommand interface { 76 Subcommand 77 } 78 79 // CreateAPISubcommand is an interface that represents a `create api` subcommand. 80 type CreateAPISubcommand interface { 81 Subcommand 82 RequiresResource 83 } 84 85 // CreateWebhookSubcommand is an interface that represents a `create wekbhook` subcommand. 86 type CreateWebhookSubcommand interface { 87 Subcommand 88 RequiresResource 89 } 90 91 // EditSubcommand is an interface that represents an `edit` subcommand. 92 type EditSubcommand interface { 93 Subcommand 94 }