Skip to content

Commit

Permalink
Fixing some flags and test
Browse files Browse the repository at this point in the history
Signed-off-by: Mohit Sharma <[email protected]>
  • Loading branch information
mohitsharma-in committed Mar 8, 2023
1 parent c97a4dd commit 445b713
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
11 changes: 3 additions & 8 deletions hack/k-license/k-license.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/*
Copyright 2023 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -31,7 +28,6 @@ var (
templatesDir = flag.String("templates", "../boilerplate", "directory containing license templates")
excludeDirs = flag.String("exclude", ".git,vendor,node_modules", "comma-separated list of directories to exclude")
path = flag.String("path", ".", "Absolute Path to directory location")
author = flag.String("author", "The Kubernetes Authors", "Replace Author/ORG name")
helpFlag = flag.Bool("help", false, "Display this help message and exit.")
)

Expand All @@ -51,7 +47,7 @@ func main() {
}
if !info.IsDir() && (isCodeFile(path) || isBuildFile(path)) && !hasLicense(path) {
currentYear := strconv.Itoa(time.Now().Year())
err := addLicense(path, *templatesDir, currentYear, *author)
err := addLicense(path, *templatesDir, currentYear)
if err != nil {
return err
}
Expand Down Expand Up @@ -131,7 +127,7 @@ func getFileType(path string) string {
return tmplFilename
}

func addLicense(path, templatesDir, year, author string) error {
func addLicense(path, templatesDir, year string) error {

tmplData, err := ioutil.ReadFile(filepath.Join(templatesDir, getFileType(path)))
if err != nil {
Expand All @@ -140,7 +136,6 @@ func addLicense(path, templatesDir, year, author string) error {

// Replace placeholders with actual values
tmpl := strings.ReplaceAll(string(tmplData), "<YYYY>", year)
tmpl = strings.ReplaceAll(tmpl, "<Organization Name>", author)

codeData, err := ioutil.ReadFile(path)
if err != nil {
Expand Down
8 changes: 3 additions & 5 deletions hack/k-license/k-license_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
/*
Copyright 2023 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
Expand All @@ -38,7 +36,7 @@ func TestAddLicense(t *testing.T) {
t.Fatal(err)
}
currentYear := strconv.Itoa(time.Now().Year())
err = addLicense(testfile, "./templates", currentYear, "")
err = addLicense(testfile, "./templates", currentYear)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 445b713

Please sign in to comment.