github.com/joshdk/godel@v0.0.0-20170529232908-862138a45aee/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 // ReleaseTag specifies the latest supported Go release tag. Empty if default should be used. 27 ReleaseTag string 28 29 // Checks specifies the configuration used by the checks. The key is the name of the check and the value is the 30 // custom configuration for that check. 31 Checks map[amalgomated.Cmd]Checker 32 33 // Exclude specifies the files that should be excluded from tests. 34 Exclude matcher.Matcher 35 } 36 37 type Checker struct { 38 // Skip specifies whether or not the check should be skipped entirely. 39 Skip bool 40 41 // Args specifies the command-line arguments provided to the check. 42 Args []string 43 44 // LineFilters specifies the filter definitions. Raw output lines that match the filter are excluded from 45 // processing. 46 LineFilters []checkoutput.Filterer 47 } 48 49 // ArgsForCheck returns the arguments for the requested check stored in the Config, or nil if no configuration for the 50 // specified check was present in the configuration. The second return value indicates whether or not configuration for 51 // the requested check was present. 52 func (p *OKGo) ArgsForCheck(check amalgomated.Cmd) ([]string, bool) { 53 checkConfig, ok := p.Checks[check] 54 if !ok { 55 return nil, false 56 } 57 return checkConfig.Args, true 58 } 59 60 // FiltersForCheck returns the filters that should be used for the requested check. The returned slice is a 61 // concatenation of the global filters derived from the package excludes specified in the configuration followed by the 62 // filters specified for the provided check in the configuration. Returns an empty slice if no filters are present 63 // globally or for the specified check.The derivation from the global filters is done in case the packages can't be 64 // excluded before the check is run (can happen if the check only supports the "all" mode). 65 func (p *OKGo) FiltersForCheck(check amalgomated.Cmd) []checkoutput.Filterer { 66 filters := append([]checkoutput.Filterer{}, checkoutput.MatcherFilter(p.Exclude)) 67 checkConfig, ok := p.Checks[check] 68 if ok { 69 filters = append(filters, checkConfig.LineFilters...) 70 } 71 return filters 72 } 73 74 func (p *OKGo) checkCommands() []amalgomated.Cmd { 75 var cmds []amalgomated.Cmd 76 for _, currCmd := range cmdlib.Instance().Cmds() { 77 if _, ok := p.Checks[currCmd]; ok { 78 cmds = append(cmds, currCmd) 79 } 80 } 81 return cmds 82 }