Skip to content

Commit

Permalink
add_golicense: user name and user email config from cmd line.
Browse files Browse the repository at this point in the history
  • Loading branch information
q191201771 committed Oct 16, 2019
1 parent 29232a0 commit f321842
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
16 changes: 9 additions & 7 deletions demo/add_go_license/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ import (
"github.com/q191201771/naza/pkg/nazalog"
)

var licenseTmpl = `// Copyright %d, Chef. All rights reserved.
var licenseTmpl = `// Copyright %d, %s. All rights reserved.
// https://%s
//
// Use of this source code is governed by a MIT-style license
// that can be found in the License file.
//
// Author: Chef ([email protected])
// Author: %s (%s)
`

func main() {
dir := parseFlag()
dir, name, email := parseFlag()

year := time.Now().Year()
repo := achieveRepo(dir)
license := fmt.Sprintf(licenseTmpl, year, repo)
license := fmt.Sprintf(licenseTmpl, year, name, repo, name, email)
nazalog.Debug(license)

var (
Expand Down Expand Up @@ -67,12 +67,14 @@ func achieveRepo(root string) string {
return string(bytes.TrimSpace(repo))
}

func parseFlag() string {
func parseFlag() (string, string, string) {
dir := flag.String("d", "", "dir of repo")
name := flag.String("n", "", "user name")
email := flag.String("e", "", "user email")
flag.Parse()
if *dir == "" {
if *dir == "" || *name == "" || *email == "" {
flag.Usage()
os.Exit(1)
}
return *dir
return *dir, *name, *email
}
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

echo '-----add_go_license-----'
if command -v add_go_license >/dev/null 2>&1; then
add_go_license -d ./
add_go_license -d ./ -e [email protected] -n Chef
else
echo 'CHEFNOTICEME add_go_license not exist!'
fi
Expand Down

0 comments on commit f321842

Please sign in to comment.