Skip to content

Commit

Permalink
skip extensions or files
Browse files Browse the repository at this point in the history
  • Loading branch information
cpanato committed Apr 28, 2021
1 parent a029431 commit ab5e2b3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Flags:
`

var (
skipExtensionFlags skipExtensionFlag

holder = flag.String("c", "Google LLC", "copyright holder")
license = flag.String("l", "apache", "license type: apache, bsd, mit, mpl")
licensef = flag.String("f", "", "license file")
Expand All @@ -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")
)

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() {
flag.Usage = func() {
fmt.Fprintln(os.Stderr, helpText)
flag.PrintDefaults()
}
flag.Var(&skipExtensionFlags, "skip", "To skip files to check/add the header file, for example: -skip rb -skip go")
flag.Parse()
if flag.NArg() == 0 {
flag.Usage()
Expand Down Expand Up @@ -161,6 +175,12 @@ func walk(ch chan<- *file, start string) {
if fi.IsDir() {
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()}
return nil
})
Expand Down Expand Up @@ -272,6 +292,7 @@ func hashBang(b []byte) []byte {

// go generate: ^// 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$
var cargoRazeGenerated = regexp.MustCompile(`(?m)^DO NOT EDIT! Replaced on runs of cargo-raze$`)

Expand Down

0 comments on commit ab5e2b3

Please sign in to comment.