skip extensions or files

This commit is contained in:
Carlos Panato
2021-04-28 11:01:02 +02:00
parent a0294312aa
commit ab5e2b3095

21
main.go
View File

@@ -48,6 +48,8 @@ Flags:
` `
var ( var (
skipExtensionFlags skipExtensionFlag
holder = flag.String("c", "Google LLC", "copyright holder") holder = flag.String("c", "Google LLC", "copyright holder")
license = flag.String("l", "apache", "license type: apache, bsd, mit, mpl") license = flag.String("l", "apache", "license type: apache, bsd, mit, mpl")
licensef = flag.String("f", "", "license file") licensef = flag.String("f", "", "license file")
@@ -56,11 +58,23 @@ var (
checkonly = flag.Bool("check", false, "check only mode: verify presence of license headers and exit with non-zero code if missing") checkonly = flag.Bool("check", false, "check only mode: verify presence of license headers and exit with non-zero code if missing")
) )
type skipExtensionFlag []string
func (i *skipExtensionFlag) String() string {
return fmt.Sprint(*i)
}
func (i *skipExtensionFlag) Set(value string) error {
*i = append(*i, value)
return nil
}
func main() { func main() {
flag.Usage = func() { flag.Usage = func() {
fmt.Fprintln(os.Stderr, helpText) fmt.Fprintln(os.Stderr, helpText)
flag.PrintDefaults() flag.PrintDefaults()
} }
flag.Var(&skipExtensionFlags, "skip", "To skip files to check/add the header file, for example: -skip rb -skip go")
flag.Parse() flag.Parse()
if flag.NArg() == 0 { if flag.NArg() == 0 {
flag.Usage() flag.Usage()
@@ -161,6 +175,12 @@ func walk(ch chan<- *file, start string) {
if fi.IsDir() { if fi.IsDir() {
return nil return nil
} }
for _, skip := range skipExtensionFlags {
if strings.TrimPrefix(filepath.Ext(fi.Name()), ".") == skip || fi.Name() == skip {
log.Printf("%s: skipping this file", fi.Name())
return nil
}
}
ch <- &file{path, fi.Mode()} ch <- &file{path, fi.Mode()}
return nil return nil
}) })
@@ -272,6 +292,7 @@ func hashBang(b []byte) []byte {
// go generate: ^// Code generated .* DO NOT EDIT\.$ // go generate: ^// Code generated .* DO NOT EDIT\.$
var goGenerated = regexp.MustCompile(`(?m)^.{1,2} Code generated .* DO NOT EDIT\.$`) var goGenerated = regexp.MustCompile(`(?m)^.{1,2} Code generated .* DO NOT EDIT\.$`)
// cargo raze: ^DO NOT EDIT! Replaced on runs of cargo-raze$ // cargo raze: ^DO NOT EDIT! Replaced on runs of cargo-raze$
var cargoRazeGenerated = regexp.MustCompile(`(?m)^DO NOT EDIT! Replaced on runs of cargo-raze$`) var cargoRazeGenerated = regexp.MustCompile(`(?m)^DO NOT EDIT! Replaced on runs of cargo-raze$`)