github.imxd.top/operator-framework/operator-sdk@v0.8.2/pkg/internal/flags/flags.go (about)

     1  // Copyright 2019 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  	"time"
    20  
    21  	"github.com/spf13/pflag"
    22  )
    23  
    24  // WatchFlags provides flag for configuration of a controller's reconcile period and for a
    25  // watches.yaml file, which is used to configure dynamic operators (e.g. Ansible and Helm).
    26  type WatchFlags struct {
    27  	ReconcilePeriod time.Duration
    28  	WatchesFile     string
    29  }
    30  
    31  // AddTo - Add the reconcile period and watches file flags to the the flagset
    32  // helpTextPrefix will allow you add a prefix to default help text. Joined by a space.
    33  func (f *WatchFlags) AddTo(flagSet *pflag.FlagSet, helpTextPrefix ...string) {
    34  	flagSet.DurationVar(&f.ReconcilePeriod,
    35  		"reconcile-period",
    36  		time.Minute,
    37  		strings.Join(append(helpTextPrefix, "Default reconcile period for controllers"), " "),
    38  	)
    39  	flagSet.StringVar(&f.WatchesFile,
    40  		"watches-file",
    41  		"./watches.yaml",
    42  		strings.Join(append(helpTextPrefix, "Path to the watches file to use"), " "),
    43  	)
    44  }