-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobaloptions.go
50 lines (39 loc) · 1.33 KB
/
globaloptions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// SPDX-FileCopyrightText: 2022 Weston Schmidt <[email protected]>
// SPDX-License-Identifier: Apache-2.0
package goschtalt
import (
"fmt"
"github.com/goschtalt/goschtalt/internal/print"
)
// GlobalOption options implement all option interfaces.
type GlobalOption interface {
fmt.Stringer
BufferOption
ExpandOption
MarshalOption
Option
UnmarshalOption
ValueOption
}
// WithError provides a way for plugins to return an error during option
// processing. This option will always produce the specified error; including
// if the err value is nil.
func WithError(err error) GlobalOption {
return errorOption{err: err}
}
type errorOption struct {
err error
}
var _ Option = (*errorOption)(nil)
func (errorOption) ignoreDefaults() bool {
return false
}
func (eo errorOption) apply(*options) error { return eo.err }
func (eo errorOption) bufferApply(*bufferOptions) error { return eo.err }
func (eo errorOption) expandApply(*expand) error { return eo.err }
func (eo errorOption) marshalApply(*marshalOptions) error { return eo.err }
func (eo errorOption) unmarshalApply(*unmarshalOptions) error { return eo.err }
func (eo errorOption) valueApply(*valueOptions) error { return eo.err }
func (eo errorOption) String() string {
return print.P("WithError", print.Error(eo.err))
}