From f321842ecc9339c5ef0ab883e825203752c76563 Mon Sep 17 00:00:00 2001 From: q191201771 <191201771@qq.com> Date: Wed, 16 Oct 2019 19:53:35 +0800 Subject: [PATCH] add_golicense: user name and user email config from cmd line. --- demo/add_go_license/main.go | 16 +++++++++------- test.sh | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/demo/add_go_license/main.go b/demo/add_go_license/main.go index 2f64221..7ce4c0b 100644 --- a/demo/add_go_license/main.go +++ b/demo/add_go_license/main.go @@ -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 (191201771@qq.com) +// 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 ( @@ -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 } diff --git a/test.sh b/test.sh index fd9002e..75d12c8 100755 --- a/test.sh +++ b/test.sh @@ -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 191201771@qq.com -n Chef else echo 'CHEFNOTICEME add_go_license not exist!' fi