lice——交互式开源许可证生成器/查看器

今天想要介绍的是一个 CLI 交互式开源许可证生成器以及查看器,它是使用 JavaScript 编写的,虽然最后更新还在 2017 年(现在已经是 2022 年了 😄 ),但是它仍然工作得很好,可以非常方便的生成我们需要的开源许可证 LICENSE 文件

安装

安装很简单,不管你的操作系统是什么,只要安装了 Node.js、NPM 或者 Yarn

1
2
3
4
5
# 使用 NPM 安装
$ npm install -g lice

# 使用 Yarn 安装
$ yarn global add lice

以 Yarn 安装为例

使用

交互式

交互式的开源许可证生成器/查看器是它的灵魂,在你想要生成 LICENSE 许可证文件的路径打开终端,输入 lice 即可进入交互式 CLI

第一个是开源许可证生成器,第二个是开源许可证查看器,选择了生成器以后,交互式 CLI 会继续询问你选择什么开源许可证

选择好我们想要的开源许可证并回车后,接下来会询问你版权持有人

最后输入年份即可

这样我们就生成了一个合适的开源许可证 LICENSE 文件

比如,截图演示的 MIT 许可证内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
The MIT License (MIT)

Copyright (c) 2022 DejavuMoe

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

非交互式

当然也可以使用非交互式使用方式,用法如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
$ lice -h
Usage:
lice [options]

Options:
-h, --help Display the help menu
-g, --generate Generate a license [default `true`]
-l, --license The type of license to generate, [default `mit`]
-n, --name The name of the generated license, [default `LICENSE`]
-p, --path License generation file path, [default `current working dir`]
-s, --show Show the contents of a license
-u, --user The name to use in the generated license [default `$LICE_USER`]
-v, --version Display the version
-y, --year Year placeholder [default `current year`]

Available licenses:
aal Attribution Assurance License (AAL)
afl-3.0 Academic Free License 3.0 (AFL-3.0)
agpl-3.0 Affero GNU Public License 3.0 (AGPL-3.0)
apache-2.0 Apache License, Verison 2.0 (Apache-2.0)
apl-1.0 Adaptive Public License (APL-1.0)
apsl-2.0 Apple Public Source License (APSL-2.0)
artistic-2.0 Artistic License (Artistic-2.0)
bsd-2-clause BSD 2-Clause "Simplified" or "FreeBSD" License (BSD-2-Clause) bsd-3-clause BSD 3-Clause "New" or "Revised" License (BSD-3-Clause)
bsl-1.0 Boost Software License (BSL-1.0)
catosl-1.1 Computer Associates Trusted Open Source License 1.1 (CATOSL-1.1)
cddl-1.0 Computer Associates Trusted Open Source License 1.0 (CDDL-1.0)
cecill-2.1 CeCILL License (CECILL-2.1)
cpal-1.0 Common Public Attribution License 1.0 (CPAL-1.0)
cua-opl-1.0 CUA Office Public License Version 1.0 (CUA-OPL-1.0)
ecl-2.0 Educational Community License, Version 2.0 (ECL-2.0)
epl-1.0 Eclipse Public License 1.0 (EPL-1.0)
entessa Entessa Public License Version 1.0 (Entessa)
eudatagrid EU Datagrid Software License (EUDatagrid)
gpl-3.0 GNU General Public License 3.0 (GPL-3.0)
isc ISC License (ISC)
mit The MIT License (MIT) [default]
mpl-2.0 Mozilla Public License Version 2.0 (MPL-2.0)
ms-pl Microsoft Public License (MS-PL)
w3c The W3C SOFTWARE NOTICE AND LICENSE
zlib-libpng The zlib/libpng License (Zlib)

lice 的源代码开源在 GitHub 上,你可以在 这里 查看它 😙

  • 阮一峰博客——如何选择开源许可证?