Skip to content

Commit

Permalink
Fixing boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
mohitsharma-in committed Mar 8, 2023
1 parent 5d35827 commit b338101
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
7 changes: 4 additions & 3 deletions hack/k-license/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

## Build

`go build -o k-license main.go `
`go build -o k-license k-license.go `

Example
To Apply header from ./templates folder default
To Apply header from ./boilerplate
folder default
```
$ k-license --path=temp
Modified temp/Dockerfile file
Expand All @@ -35,7 +36,7 @@ Options:
-path string
Absolute Path to directory location (default ".")
-templates string
directory containing license templates (default "./templates")
directory containing license templates (default "./boilerplate")
Examples:
./k-lic # Add license headers to all source files in the current directory and its subdirectories, using the default file extensions and templates directory.
Expand Down
8 changes: 5 additions & 3 deletions hack/k-license/k-license.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/*
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
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 Down Expand Up @@ -135,14 +138,13 @@ func addLicense(path, templatesDir, year string) error {
}

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

tmpl := strings.ReplaceAll(string(tmplData), "YEAR", year)
codeData, err := ioutil.ReadFile(path)
if err != nil {
return err
}

newData := append([]byte(tmpl), []byte("\n\n")...)
newData := append([]byte(tmpl), []byte("\n")...)
newData = append(newData, codeData...)

return ioutil.WriteFile(path, newData, 0644)
Expand Down
3 changes: 3 additions & 0 deletions hack/k-license/k-license_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/*
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
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 Down

0 comments on commit b338101

Please sign in to comment.