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