-
Notifications
You must be signed in to change notification settings - Fork 46
/
policy_options.go
49 lines (40 loc) · 1.19 KB
/
policy_options.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
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
package policy
// Option is a functional option used to pass in arguments to a Policy.
type Option func(*Options)
// Options defines the set of options available to a Policy.
type Options struct {
CommitMsgFile *string
CommitRef string
RevisionRange string
}
// WithCommitMsgFile sets the path to the commit message file.
func WithCommitMsgFile(o *string) Option {
return func(args *Options) {
args.CommitMsgFile = o
}
}
// WithCommitRef sets the ref to compare git policies against.
func WithCommitRef(o string) Option {
return func(args *Options) {
args.CommitRef = o
}
}
// WithRevisionRange sets the revision range to compare git policies against.
func WithRevisionRange(o string) Option {
return func(args *Options) {
args.RevisionRange = o
}
}
// NewDefaultOptions initializes a Options struct with default values.
func NewDefaultOptions(setters ...Option) *Options {
opts := &Options{
CommitMsgFile: nil,
}
for _, setter := range setters {
setter(opts)
}
return opts
}