Go (Golang) 工具之copyright 添加 | go源码添加授权头

Go (Golang) 工具之copyright 添加 | go源码添加版权

什么是addlicense

github.com/marmotedu/addlicense

自动在一个或多个源代码文件的顶部插入指定的许可证文件或版权信息。

addlicense安装和使用

安装

$ go get -u github.com/marmotedu/addlicense

帮助信息为:

$ addlicense -h
Usage: addlicense [flags] pattern [pattern ...]

The program ensures source code files have copyright license headers
by scanning directory patterns recursively.

It modifies all source files in place and avoids adding a license header
to any file that already has one.

The pattern argument can be provided multiple times, and may also refer
to single files.

Flags:

      --check                check only mode: verify presence of license headers and exit with non-zero code if missing
  -h, --help                 show this help message
  -c, --holder string        copyright holder (default "Google LLC")
  -l, --license string       license type: apache, bsd, mit, mpl (default "apache")
  -f, --licensef string      custom license file (no default)
      --skip-dirs strings    regexps of directories to skip
      --skip-files strings   regexps of files to skip
  -v, --verbose              verbose mode: print the name of the files that are modified
  -y, --year string          copyright year(s) (default "2021")

参数说明:

  • –check 只检查
  • -f, --licensef 指定版权头文件
  • -v 打印被更改的文件
  • –skip-dirs 跳过指定的文件夹

使用方法:
创建版权头文件

$ cat ./boilerplate.txt
Copyright 2020 Lingfei Kong <colin404@foxmail.com>. All rights reserved.
Use of this source code is governed by a MIT style
license that can be found in the LICENSE file.

检查文件中是否都有该版权头

$ addlicense --check -f ./boilerplate.txt . --skip-dirs=third_party

给缺失版权头的文件添加版权头

$ addlicense -v -f ./boilerplate.txt . --skip-dirs=third_party
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西京刀客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值