mirror of
https://github.com/mgechev/revive.git
synced 2025-01-24 03:47:45 +02:00
Fail in case of invalid input directories
This commit is contained in:
parent
b59982cd81
commit
00d809748e
@ -142,17 +142,32 @@ func defaultConfig() *lint.Config {
|
|||||||
return &defaultConfig
|
return &defaultConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func normalizeSplit(strs []string) []string {
|
||||||
|
res := []string{}
|
||||||
|
for _, s := range strs {
|
||||||
|
t := strings.Trim(s, " \t")
|
||||||
|
if len(t) > 0 {
|
||||||
|
res = append(res, t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
func getFiles() []string {
|
func getFiles() []string {
|
||||||
globs := flag.Args()
|
globs := normalizeSplit(flag.Args())
|
||||||
if len(globs) == 0 {
|
if len(globs) == 0 {
|
||||||
fail("files not specified")
|
fail("files not specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
files, errs := dots.Resolve(globs, strings.Split(excludePaths, " "))
|
files, errs := dots.Resolve(globs, normalizeSplit(excludePaths))
|
||||||
if errs != nil && len(errs) > 0 {
|
if errs != nil && len(errs) > 0 {
|
||||||
err := ""
|
err := ""
|
||||||
for _, e := range errs {
|
for i, e := range errs {
|
||||||
err += e.Error() + "\n"
|
suffix := "\n"
|
||||||
|
if i == len(errs)-1 {
|
||||||
|
suffix = ""
|
||||||
|
}
|
||||||
|
err += e.Error() + suffix
|
||||||
}
|
}
|
||||||
fail(err)
|
fail(err)
|
||||||
}
|
}
|
||||||
@ -160,8 +175,19 @@ func getFiles() []string {
|
|||||||
return files
|
return files
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type arrayFlags []string
|
||||||
|
|
||||||
|
func (i *arrayFlags) String() string {
|
||||||
|
return strings.Join([]string(*i), " ")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i *arrayFlags) Set(value string) error {
|
||||||
|
*i = append(*i, value)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var configPath string
|
var configPath string
|
||||||
var excludePaths string
|
var excludePaths arrayFlags
|
||||||
var formatterName string
|
var formatterName string
|
||||||
var help bool
|
var help bool
|
||||||
|
|
||||||
@ -173,12 +199,12 @@ func init() {
|
|||||||
originalUsage()
|
originalUsage()
|
||||||
}
|
}
|
||||||
const (
|
const (
|
||||||
configUsage = "path to the configuration TOML file"
|
configUsage = "path to the configuration TOML file (i.e. -config myconf.toml)"
|
||||||
excludeUsage = "glob which specifies files to be excluded"
|
excludeUsage = "list of globs which specify files to be excluded (i.e. -exclude foo/...)"
|
||||||
formatterUsage = "formatter to be used for the output"
|
formatterUsage = "formatter to be used for the output (i.e. -formatter cli)"
|
||||||
)
|
)
|
||||||
flag.StringVar(&configPath, "config", "", configUsage)
|
flag.StringVar(&configPath, "config", "", configUsage)
|
||||||
flag.StringVar(&excludePaths, "exclude", "", excludeUsage)
|
flag.Var(&excludePaths, "exclude", excludeUsage)
|
||||||
flag.StringVar(&formatterName, "formatter", "", formatterUsage)
|
flag.StringVar(&formatterName, "formatter", "", formatterUsage)
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user