diff --git a/README.md b/README.md index 2392259..11887c5 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,11 @@ to any file that already has one. ## usage addlicense [flags] pattern [pattern ...] - + -c copyright holder (default "Google LLC.") + -f custom license file (no default) -l license type: apache, bsd, mit (default "apache") - -y year (default 2016) + -y year (default "2018") The pattern argument can be provided multiple times, and may also refer to single files. diff --git a/main.go b/main.go index 90a0445..21e317d 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,4 @@ -// Copyright 2016 Google Inc. +// Copyright 2018 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -135,16 +135,16 @@ func walk(ch chan<- *file, start string) { func addLicense(path string, fmode os.FileMode, tmpl *template.Template, data *copyrightData) error { var lic []byte var err error - switch filepath.Ext(path) { + switch fileExtension(path) { default: return nil case ".c", ".h": lic, err = prefix(tmpl, data, "/*", " * ", " */") case ".js", ".jsx", ".tsx", ".css", ".tf": lic, err = prefix(tmpl, data, "/**", " * ", " */") - case ".cc", ".cpp", ".cs", ".go", ".hh", ".hpp", ".java", ".m", ".mm", ".proto", ".rs", ".scala", ".swift", ".dart": + case ".cc", ".cpp", ".cs", ".go", ".hh", ".hpp", ".java", ".m", ".mm", ".proto", ".rs", ".scala", ".swift", ".dart", ".groovy": lic, err = prefix(tmpl, data, "", "// ", "") - case ".py", ".sh", ".yaml", ".yml": + case ".py", ".sh", ".yaml", ".yml", ".dockerfile", "dockerfile", ".rb", "gemfile": lic, err = prefix(tmpl, data, "", "# ", "") case ".el", ".lisp": lic, err = prefix(tmpl, data, "", ";; ", "") @@ -178,10 +178,19 @@ func addLicense(path string, fmode os.FileMode, tmpl *template.Template, data *c return ioutil.WriteFile(path, b, fmode) } +func fileExtension(name string) string { + if v := filepath.Ext(name); v != "" { + return strings.ToLower(v) + } + return strings.ToLower(filepath.Base(name)) +} + var head = []string{ - "#!", // shell script - "