Skip to content

Commit

Permalink
fix(plugin-common): hidden options should not be displayed in help
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jan 28, 2020
1 parent 5f8d8e1 commit 6b1530a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
8 changes: 4 additions & 4 deletions packages/plugin-common/src/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,15 @@ async function showCommandHelp (command: Command, meta: Meta<'message'>, options
output.push(command._usage)
}

if (command._options.length) {
const options = command._options.filter(option => !option.hidden)
if (options.some(o => o.authority)) {
const _options = command._options.filter(option => !option.hidden)
if (_options.length) {
if (_options.some(o => o.authority)) {
output.push('可用的选项有(括号内为额外要求的权限等级):')
} else {
output.push('可用的选项有:')
}

command._options.filter(option => !option.hidden).forEach((option) => {
_options.forEach((option) => {
const authority = option.authority ? `(${option.authority}) ` : ''
let line = ` ${authority}${option.rawName} ${option.description}`
if (option.notUsage && maxUsage !== Infinity) {
Expand Down
16 changes: 2 additions & 14 deletions packages/plugin-common/tests/__snapshots__/help.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ Array [
"bar.baz
command with alias and shortcut
中文别名:baz-alias。
相关全局指令:baz-shortcut。
可用的选项有:
-h, --help 显示本信息",
相关全局指令:baz-shortcut。",
]
`;

Expand All @@ -22,9 +20,7 @@ Array [
"bar.baz
command with alias and shortcut
中文别名:baz-alias。
相关全局指令:baz-shortcut。
可用的选项有:
-h, --help 显示本信息",
相关全局指令:baz-shortcut。",
]
`;

Expand Down Expand Up @@ -65,8 +61,6 @@ Array [
"bar
command with usage and examples
usage text
可用的选项有:
-h, --help 显示本信息
使用示例:
example 1
example 2
Expand All @@ -82,7 +76,6 @@ command with options
已调用次数:0/100。
距离下次调用还需:0/1 秒。
可用的选项有(括号内为额外要求的权限等级):
-h, --help 显示本信息
(2) -o [value] option(不计入总次数)",
]
`;
Expand All @@ -93,7 +86,6 @@ Array [
显示帮助信息
相关全局指令:帮助,全局指令。
可用的选项有:
-h, --help 显示本信息
-e, --expand 展开指令列表
-s, --shortcut 查看全局指令列表
可用的子指令有(括号内为对应的最低权限等级,标有星号的表示含有子指令):
Expand All @@ -107,7 +99,6 @@ Array [
显示帮助信息
相关全局指令:帮助,全局指令。
可用的选项有:
-h, --help 显示本信息
-e, --expand 展开指令列表
-s, --shortcut 查看全局指令列表
可用的子指令有(括号内为对应的最低权限等级,标有星号的表示含有子指令):
Expand All @@ -121,7 +112,6 @@ Array [
显示帮助信息
相关全局指令:帮助,全局指令。
可用的选项有:
-h, --help 显示本信息
-e, --expand 展开指令列表
-s, --shortcut 查看全局指令列表
可用的子指令有(括号内为对应的最低权限等级,标有星号的表示含有子指令):
Expand All @@ -144,7 +134,6 @@ command with options
已调用次数:1/100。
距离下次调用还需:1/1 秒。
可用的选项有(括号内为额外要求的权限等级):
-h, --help 显示本信息
(2) -o [value] option(不计入总次数)",
]
`;
Expand All @@ -154,7 +143,6 @@ Array [
"foo
command with options
可用的选项有(括号内为额外要求的权限等级):
-h, --help 显示本信息
(2) -o [value] option(不计入总次数)",
]
`;

0 comments on commit 6b1530a

Please sign in to comment.