mirror of
https://github.com/kairos-io/kairos-sdk.git
synced 2025-04-27 19:15:23 +00:00
Relates to kairos-io/kairos#2492 Signed-off-by: Mauro Morales <mauro.morales@spectrocloud.com>
83 lines
1.5 KiB
Go
83 lines
1.5 KiB
Go
package collector
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
type Options struct {
|
|
ScanDir []string
|
|
BootCMDLineFile string
|
|
MergeBootCMDLine bool
|
|
NoLogs bool
|
|
StrictValidation bool
|
|
Readers []io.Reader
|
|
Overwrites string
|
|
}
|
|
|
|
type Option func(o *Options) error
|
|
|
|
var NoLogs Option = func(o *Options) error {
|
|
o.NoLogs = true
|
|
return nil
|
|
}
|
|
|
|
// SoftErr prints a warning if err is no nil and NoLogs is not true.
|
|
// It's use to wrap the same handling happening in multiple places.
|
|
//
|
|
// TODO: Switch to a standard logging library (e.g. verbose, silent mode etc).
|
|
func (o *Options) SoftErr(message string, err error) {
|
|
if !o.NoLogs && err != nil {
|
|
fmt.Printf("WARNING: %s, %s\n", message, err.Error())
|
|
}
|
|
}
|
|
|
|
func (o *Options) Apply(opts ...Option) error {
|
|
for _, oo := range opts {
|
|
if err := oo(o); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
var MergeBootLine = func(o *Options) error {
|
|
o.MergeBootCMDLine = true
|
|
return nil
|
|
}
|
|
|
|
func WithBootCMDLineFile(s string) Option {
|
|
return func(o *Options) error {
|
|
o.BootCMDLineFile = s
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func StrictValidation(v bool) Option {
|
|
return func(o *Options) error {
|
|
o.StrictValidation = v
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func Directories(d ...string) Option {
|
|
return func(o *Options) error {
|
|
o.ScanDir = d
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func Readers(r ...io.Reader) Option {
|
|
return func(o *Options) error {
|
|
o.Readers = r
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func Overwrites(m string) Option {
|
|
return func(o *Options) error {
|
|
o.Overwrites = m
|
|
return nil
|
|
}
|
|
}
|