github.com/autonomy/conform@v0.1.0-alpha.16/internal/policy/policy_options.go (about)

     1  /* This Source Code Form is subject to the terms of the Mozilla Public
     2   * License, v. 2.0. If a copy of the MPL was not distributed with this
     3   * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     4  
     5  package policy
     6  
     7  // Option is a functional option used to pass in arguments to a Policy.
     8  type Option func(*Options)
     9  
    10  // Options defines the set of options available to a Policy.
    11  type Options struct {
    12  	CommitMsgFile *string
    13  }
    14  
    15  // WithCommitMsgFile sets the path to the commit message file.
    16  func WithCommitMsgFile(o *string) Option {
    17  	return func(args *Options) {
    18  		args.CommitMsgFile = o
    19  	}
    20  }
    21  
    22  // NewDefaultOptions initializes a Options struct with default values.
    23  func NewDefaultOptions(setters ...Option) *Options {
    24  	opts := &Options{
    25  		CommitMsgFile: nil,
    26  	}
    27  
    28  	for _, setter := range setters {
    29  		setter(opts)
    30  	}
    31  
    32  	return opts
    33  }