new-post / new-thought:漏参数时先说清原因,不再像脚本崩了
无参数调用时脚本会打印用法并 exit 1(语义是对的:缺必填参数), 但 pnpm 会再补一句 "[ELIFECYCLE] Command failed with exit code 1", 看起来像脚本崩了而不是用法提示。 改成在用法前面先输出一行: 缺少正文内容,没有创建任何文件。 正确写法:pnpm new-thought "今天把树莓派的散热换掉了。" exit 码不变(无参数 1、--help 0),只是把原因说清楚。
This commit is contained in:
@@ -24,6 +24,11 @@ function today() {
|
||||
const args = process.argv.slice(2)
|
||||
|
||||
if (args.length === 0 || args[0] === "--help" || args[0] === "-h") {
|
||||
// 无参数进来时先说清楚原因:下面 pnpm 还会补一句
|
||||
// "[ELIFECYCLE] Command failed with exit code 1",不点明的话很像脚本崩了
|
||||
if (args.length === 0) {
|
||||
console.log('缺少文章标题,没有创建任何文件。\n正确写法:pnpm new-post "树莓派装 Docker 全程记录" --category 教程\n')
|
||||
}
|
||||
console.log(`创建一篇新文章
|
||||
|
||||
用法:
|
||||
|
||||
@@ -33,6 +33,11 @@ function fileStamp() {
|
||||
const args = process.argv.slice(2)
|
||||
|
||||
if (args.length === 0 || args[0] === "--help" || args[0] === "-h") {
|
||||
// 无参数进来时先说清楚原因:下面 pnpm 还会补一句
|
||||
// "[ELIFECYCLE] Command failed with exit code 1",不点明的话很像脚本崩了
|
||||
if (args.length === 0) {
|
||||
console.log('缺少正文内容,没有创建任何文件。\n正确写法:pnpm new-thought "今天把树莓派的散热换掉了。"\n')
|
||||
}
|
||||
console.log(`创建一条新的「偶得」
|
||||
|
||||
用法:
|
||||
|
||||
Reference in New Issue
Block a user