1. demo/add_blog_license 给blog的文章尾部添加版权声明 2. 在test.sh中给go文件添加头部MIT声明

pull/2/head
q191201771 5 years ago
parent 1dc7b7da59
commit 9362f98862

1
.gitignore vendored

@ -10,3 +10,4 @@ tmp
/TODO.md
/pkg/tag
/pkg/taskpool

@ -11,19 +11,49 @@ package main
import (
"bytes"
"flag"
"fmt"
"github.com/q191201771/naza/pkg/filebatch"
"github.com/q191201771/naza/pkg/nazalog"
"os"
"strings"
)
var licenseTmpl = `
> **** [https://pengrl.com/p/%s/](https://pengrl.com/p/%s/)
> **** `
func main() {
dir := parseFlag()
linesOfLicense := strings.Split(licenseTmpl, "\n")
lastLineOfLicense := linesOfLicense[len(linesOfLicense)-1]
var (
skipCount int
modCount int
)
err := filebatch.Walk(dir, true, ".md", func(path string, info os.FileInfo, content []byte) []byte {
lines := bytes.Split(content, []byte{'\n'})
nazalog.Debug(path, len(lines))
return nil
if bytes.Index(lines[len(lines)-1], []byte(lastLineOfLicense)) != -1 {
skipCount++
return nil
}
var abbrlink string
for _, line := range lines {
if bytes.Index(line, []byte("abbrlink")) != -1 {
abbrlink = string(bytes.TrimSpace(bytes.Split(line, []byte{':'})[1]))
nazalog.Debug(abbrlink)
break
}
}
modCount++
license := fmt.Sprintf(licenseTmpl, abbrlink, abbrlink)
return filebatch.AddTailContent(content, []byte(license))
})
nazalog.FatalIfErrorNotNil(err)
nazalog.Infof("count. mod=%d, skip=%d", modCount, skipCount)
}
func parseFlag() string {

@ -20,7 +20,7 @@ import (
"time"
)
var license = `// Copyright %d, Chef. All rights reserved.
var licenseTmpl = `// Copyright %d, Chef. All rights reserved.
// https://%s
//
// Use of this source code is governed by a MIT-style license
@ -35,8 +35,8 @@ func main() {
year := time.Now().Year()
repo := achieveRepo(dir)
head := fmt.Sprintf(license, year, repo)
nazalog.Debug(head)
license := fmt.Sprintf(licenseTmpl, year, repo)
nazalog.Debug(license)
var (
skipCount int
@ -52,7 +52,7 @@ func main() {
}
modCount++
return filebatch.AddHeadContent(content, []byte(head))
return filebatch.AddHeadContent(content, []byte(license))
})
nazalog.FatalIfErrorNotNil(err)
nazalog.Infof("count. mod=%d, skip=%d", modCount, skipCount)

@ -1,8 +1,10 @@
#!/usr/bin/env bash
# 在 macos 下运行 gofmt 检查
uname=$(uname)
if [[ "$uname" == "Darwin" ]]; then
# 在我的开发环境下额外做一些工作
if [[ $IS_CHEF_DEV_ENV == "true" ]]; then
echo "CHEFERASEME run add_go_license..."
add_go_license -d ./
echo "CHEFERASEME run gofmt check..."
gofiles=$(git diff --name-only --diff-filter=ACM | grep '.go$')
if [ ! -z "$gofiles" ]; then
@ -20,8 +22,6 @@ if [[ "$uname" == "Darwin" ]]; then
else
echo "CHEFERASEME mod gofiles not exist."
fi
else
echo "CHEFERASEME not run gofmt check..."
fi
# 跑 go test 生成测试覆盖率

Loading…
Cancel
Save