sigs.k8s.io/kubebuilder/v3@v3.14.0/pkg/plugins/common/kustomize/v2/create.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 v2
    18  
    19  import (
    20  	"strconv"
    21  
    22  	"github.com/spf13/pflag"
    23  
    24  	"sigs.k8s.io/kubebuilder/v3/pkg/config"
    25  	"sigs.k8s.io/kubebuilder/v3/pkg/model/resource"
    26  )
    27  
    28  type createSubcommand struct {
    29  	config   config.Config
    30  	resource *resource.Resource
    31  
    32  	flagSet *pflag.FlagSet
    33  
    34  	// force indicates whether to scaffold files even if they exist.
    35  	force bool
    36  }
    37  
    38  func (p *createSubcommand) BindFlags(fs *pflag.FlagSet) { p.flagSet = fs }
    39  
    40  func (p *createSubcommand) InjectConfig(c config.Config) error {
    41  	p.config = c
    42  	return nil
    43  }
    44  
    45  func (p *createSubcommand) InjectResource(res *resource.Resource) error {
    46  	p.resource = res
    47  	return nil
    48  }
    49  
    50  func (p *createSubcommand) configure() (err error) {
    51  	if forceFlag := p.flagSet.Lookup("force"); forceFlag != nil {
    52  		if p.force, err = strconv.ParseBool(forceFlag.Value.String()); err != nil {
    53  			return err
    54  		}
    55  
    56  	}
    57  	return nil
    58  }