github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/internal/fs/client/initoptions.templ (about)

     1  // generated code; DO NOT EDIT
     2  
     3  package {{ .Package }}
     4  
     5  import (
     6  	"time"
     7  	"github.com/sirupsen/logrus"
     8  )
     9  
    10  type initOptions struct {
    11  	cfgFile string
    12  	logger  *logrus.Entry
    13  	ns NodeSource
    14  	dt time.Duration
    15  	progress bool
    16  }
    17  
    18  // InitializationOption is an optional setting used to initialize the client
    19  type InitializationOption func(opts *initOptions)
    20  
    21  // Logger sets the logger to use else one is made via the Choria framework
    22  func Logger(l *logrus.Entry) InitializationOption {
    23  	return func(o *initOptions) {
    24  		o.logger = l
    25  	}
    26  }
    27  
    28  // Discovery sets the NodeSource to use when finding nodes to manage
    29  func Discovery(ns NodeSource) InitializationOption {
    30  	return func(o *initOptions) {
    31  		o.ns = ns
    32  	}
    33  }
    34  
    35  // Progress enables displaying a progress bar
    36  func Progress() InitializationOption {
    37  	return func(o *initOptions) {
    38  		o.progress = true
    39  	}
    40  }
    41  
    42  // DiscoveryMethod accepts a discovery method name as supplied from the CLI and configures the correct NodeSource
    43  // reverts to broadcast method if an unsupported method is supplied, custom node sources can be set using Discovery()
    44  func DiscoveryMethod(m string) InitializationOption {
    45  	return func(o *initOptions) {
    46  		switch m {
    47  		case "choria", "puppetdb", "pdb":
    48  			o.ns = &PuppetDBNS{}
    49  		default:
    50  			o.ns = &BroadcastNS{}
    51  		}
    52  	}
    53  }
    54  
    55  
    56  // DiscoveryTimeout sets a timeout for discovery for those methods that support it
    57  func DiscoveryTimeout(t time.Duration) InitializationOption {
    58  	return func(o *initOptions) {
    59  		o.dt = t
    60  	}
    61  }