github.com/lablabs/operator-sdk@v0.8.2/pkg/ansible/flags/flag.go (about)

     1  // Copyright 2018 The Operator-SDK Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package flags
    16  
    17  import (
    18  	"strings"
    19  
    20  	"github.com/operator-framework/operator-sdk/pkg/internal/flags"
    21  	"github.com/operator-framework/operator-sdk/pkg/log/zap"
    22  	"github.com/spf13/pflag"
    23  )
    24  
    25  // AnsibleOperatorFlags - Options to be used by an ansible operator
    26  type AnsibleOperatorFlags struct {
    27  	flags.WatchFlags
    28  	InjectOwnerRef bool
    29  	MaxWorkers     int
    30  }
    31  
    32  // AddTo - Add the ansible operator flags to the the flagset
    33  // helpTextPrefix will allow you add a prefix to default help text. Joined by a space.
    34  func AddTo(flagSet *pflag.FlagSet, helpTextPrefix ...string) *AnsibleOperatorFlags {
    35  	aof := &AnsibleOperatorFlags{}
    36  	aof.WatchFlags.AddTo(flagSet, helpTextPrefix...)
    37  	flagSet.AddFlagSet(zap.FlagSet())
    38  	flagSet.BoolVar(&aof.InjectOwnerRef,
    39  		"inject-owner-ref",
    40  		true,
    41  		strings.Join(append(helpTextPrefix, "The ansible operator will inject owner references unless this flag is false"), " "),
    42  	)
    43  	flagSet.IntVar(&aof.MaxWorkers,
    44  		"max-workers",
    45  		1,
    46  		strings.Join(append(helpTextPrefix,
    47  			"Maximum number of workers to use. Overridden by environment variable."),
    48  			" "),
    49  	)
    50  	return aof
    51  }