github.com/jdhenke/godel@v0.0.0-20161213181855-abeb3861bf0d/apps/okgo/params/params.go (about)

     1  // Copyright 2016 Palantir Technologies, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package params
    16  
    17  import (
    18  	"github.com/palantir/amalgomate/amalgomated"
    19  	"github.com/palantir/pkg/matcher"
    20  
    21  	"github.com/palantir/godel/apps/okgo/checkoutput"
    22  	"github.com/palantir/godel/apps/okgo/cmd/cmdlib"
    23  )
    24  
    25  type OKGo struct {
    26  	// Checks specifies the configuration used by the checks. The key is the name of the check and the value is the
    27  	// custom configuration for that check.
    28  	Checks map[amalgomated.Cmd]Checker
    29  
    30  	// Exclude specifies the files that should be excluded from tests.
    31  	Exclude matcher.Matcher
    32  }
    33  
    34  type Checker struct {
    35  	// Skip specifies whether or not the check should be skipped entirely.
    36  	Skip bool
    37  
    38  	// Args specifies the commnand-line arguments provided to the check.
    39  	Args []string
    40  
    41  	// LineFilters specifies the filter definitions. Raw output lines that match the filter are excluded from
    42  	// processing.
    43  	LineFilters []checkoutput.Filterer
    44  }
    45  
    46  // ArgsForCheck returns the arguments for the requested check stored in the Config, or nil if no configuration for the
    47  // specified check was present in the configuration. The second return value indicates whether or not configuration for
    48  // the requested check was present.
    49  func (p *OKGo) ArgsForCheck(check amalgomated.Cmd) ([]string, bool) {
    50  	checkConfig, ok := p.Checks[check]
    51  	if !ok {
    52  		return nil, false
    53  	}
    54  	return checkConfig.Args, true
    55  }
    56  
    57  // FiltersForCheck returns the filters that should be used for the requested check. The returned slice is a
    58  // concatenation of the global filters derived from the package excludes specified in the configuration followed by the
    59  // filters specified for the provided check in the configuration. Returns an empty slice if no filters are present
    60  // globally or for the specified check.The derivation from the global filters is done in case the packages can't be
    61  // excluded before the check is run (can happen if the check only supports the "all" mode).
    62  func (p *OKGo) FiltersForCheck(check amalgomated.Cmd) []checkoutput.Filterer {
    63  	filters := append([]checkoutput.Filterer{}, checkoutput.MatcherFilter(p.Exclude))
    64  	checkConfig, ok := p.Checks[check]
    65  	if ok {
    66  		filters = append(filters, checkConfig.LineFilters...)
    67  	}
    68  	return filters
    69  }
    70  
    71  func (p *OKGo) checkCommands() []amalgomated.Cmd {
    72  	var cmds []amalgomated.Cmd
    73  	for _, currCmd := range cmdlib.Instance().Cmds() {
    74  		if _, ok := p.Checks[currCmd]; ok {
    75  			cmds = append(cmds, currCmd)
    76  		}
    77  	}
    78  	return cmds
    79  }