Skip to content

Commit 4fcbc0e

Browse files
feat(parser)!: removed multiple flag aliases (#322)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent ea92027 commit 4fcbc0e

13 files changed

Lines changed: 110 additions & 159 deletions

File tree

docs/guide/flags.md

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,31 @@ It's recommended to use camelCase for flag names as it will be interpreted as pa
1919

2020
The flag type function can be any function that accepts a string and returns the parsed value. The default JavaScript constructors should cover most use cases: [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/String), [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/Number), [Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/Boolean), etc.
2121

22-
The flag description object can be used to store additional information about the flag, such as `alias`, `default`, and `description`. To accept multiple values for a flag, wrap the type function in an array.
22+
The flag description object can be used to store additional information about the flag, such as `short`, `default`, and `description`. To accept multiple values for a flag, wrap the type function in an array.
2323

2424
All provided information will be used to generate better help documentation.
2525

26-
## Flag Aliases
26+
## Flag Short Names
2727

28-
Flag aliases allow users to use shorter or alternative names for flags. This is useful for providing convenient shortcuts for commonly used flags.
28+
Flag short names allow users to use single-character shortcuts for flags. This is useful for providing convenient shortcuts for commonly used flags.
2929

30-
### Single Alias
30+
### Defining Short Names
3131

32-
You can define a single alias for a flag using a string:
32+
You can define a single-character short name for a flag using the `short` property:
3333

3434
```ts
3535
const cli = Cli()
3636
.command("build", "Build the project", {
3737
flags: {
3838
output: {
3939
type: String,
40-
alias: "o",
40+
short: "o",
4141
description: "Output directory",
4242
},
4343

4444
verbose: {
4545
type: Boolean,
46-
alias: "v",
46+
short: "v",
4747
description: "Enable verbose output",
4848
},
4949
},
@@ -59,62 +59,34 @@ const cli = Cli()
5959
.parse();
6060
```
6161

62-
### Multiple Aliases
62+
### Validation Rules
6363

64-
You can define multiple aliases for a flag using an array:
64+
- Flag names must be at least 2 characters long
65+
- The `short` property must be exactly 1 character
6566

66-
```ts
67-
const cli = Cli()
68-
.command("config", "Configure the application", {
69-
flags: {
70-
config: {
71-
type: String,
72-
alias: ["c", "cfg"],
73-
description: "Configuration file path",
74-
},
75-
76-
format: {
77-
type: String,
78-
alias: ["f", "fmt"],
79-
description: "Output format",
80-
},
81-
},
82-
})
83-
.on("config", (ctx) => {
84-
// All of these work:
85-
// $ node cli.mjs config --config file.json
86-
// $ node cli.mjs config -c file.json
87-
// $ node cli.mjs config -cfg file.json
88-
// $ node cli.mjs config --format json
89-
// $ node cli.mjs config -f json
90-
// $ node cli.mjs config -fmt json
91-
})
92-
.parse();
93-
```
94-
95-
### Combined Short Aliases
67+
### Combined Short Names
9668

97-
When using short aliases (single characters), they can be combined together:
69+
When using short names (single characters), they can be combined together:
9870

9971
```ts
10072
const cli = Cli()
10173
.command("compress", "Compress files", {
10274
flags: {
10375
output: {
10476
type: String,
105-
alias: "o",
77+
short: "o",
10678
description: "Output file",
10779
},
10880

10981
verbose: {
11082
type: Boolean,
111-
alias: "v",
83+
short: "v",
11284
description: "Verbose output",
11385
},
11486

11587
recursive: {
11688
type: Boolean,
117-
alias: "r",
89+
short: "r",
11890
description: "Recursive mode",
11991
},
12092
},
@@ -153,7 +125,7 @@ const cli = Cli()
153125
someNumber: {
154126
// Wrap the type function in an array to allow multiple values
155127
type: [Number],
156-
alias: "n",
128+
short: "n",
157129
description: "Array of numbers. (e.g. -n 1 -n 2 -n 3)",
158130
},
159131

docs/guide/types.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const cli = Cli()
3333

3434
message: {
3535
type: String,
36-
alias: "m",
36+
short: "m",
3737
description: "Greeting message",
3838
},
3939
},
@@ -66,7 +66,7 @@ const cli = Cli()
6666

6767
watch: {
6868
type: Boolean,
69-
alias: "w",
69+
short: "w",
7070
description: "Enable watch mode",
7171
},
7272
},
@@ -135,14 +135,14 @@ const cli = Cli()
135135
// Use [String] to accept multiple string values
136136
include: {
137137
type: [String],
138-
alias: "i",
138+
short: "i",
139139
description: "File patterns to include",
140140
},
141141

142142
// Use [Number] to accept multiple numeric values
143143
ports: {
144144
type: [Number],
145-
alias: "p",
145+
short: "p",
146146
description: "Ports to listen on",
147147
},
148148
},
@@ -172,7 +172,7 @@ const cli = Cli()
172172
// [Boolean] type counts how many times the flag is used
173173
verbose: {
174174
type: [Boolean],
175-
alias: "v",
175+
short: "v",
176176
description: "Verbosity level (-v, -vv, -vvv)",
177177
},
178178
},
@@ -205,7 +205,7 @@ const cli = Cli()
205205
flags: {
206206
define: {
207207
type: Object,
208-
alias: "d",
208+
short: "d",
209209
description: "Define environment variables",
210210
},
211211
},
@@ -467,7 +467,7 @@ const cli = Cli()
467467
// Use [CommaSeparatedList] to accept multiple comma-separated lists
468468
patterns: {
469469
type: [CommaSeparatedList],
470-
alias: "p",
470+
short: "p",
471471
description: "File patterns (comma-separated)",
472472
},
473473
},

docs/zh/guide/flags.md

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,31 @@ _Clerc_ 的选项解析由 [`@clerc/parser`](https://github.com/clercjs/clerc/bl
1919

2020
选项类型函数可以是任何接受字符串并返回解析后的值的函数。默认的 JavaScript 构造函数应该涵盖大多数用例:[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/String)[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/Number)[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean/Boolean) 等。
2121

22-
选项描述对象可用于存储有关选项的其他信息,例如 `alias``default``description`。要接受选项的多个值,请将类型函数包装在数组中。
22+
选项描述对象可用于存储有关选项的其他信息,例如 `short``default``description`。要接受选项的多个值,请将类型函数包装在数组中。
2323

2424
所有提供的信息将用于生成更好的帮助文档。
2525

26-
## 选项别名
26+
## 选项短名称
2727

28-
选项别名允许用户使用更短的或替代的名称来指定选项。这对于为常用的选项提供便捷的快捷方式很有用。
28+
选项短名称允许用户使用单个字符来指定选项。这对于为常用的选项提供便捷的快捷方式很有用。
2929

30-
### 单个别名
30+
### 定义短名称
3131

32-
你可以使用字符串为选项定义单个别名
32+
你可以使用`short`属性为选项定义一个单字符的短名称
3333

3434
```ts
3535
const cli = Cli()
3636
.command("build", "构建项目", {
3737
flags: {
3838
output: {
3939
type: String,
40-
alias: "o",
40+
short: "o",
4141
description: "输出目录",
4242
},
4343

4444
verbose: {
4545
type: Boolean,
46-
alias: "v",
46+
short: "v",
4747
description: "启用详细输出",
4848
},
4949
},
@@ -59,62 +59,34 @@ const cli = Cli()
5959
.parse();
6060
```
6161

62-
### 多个别名
62+
### 验证规则
6363

64-
你可以使用数组为选项定义多个别名:
64+
- flag名称必须至少包含2个字符
65+
- `short`属性必须恰好为1个字符
6566

66-
```ts
67-
const cli = Cli()
68-
.command("config", "配置应用", {
69-
flags: {
70-
config: {
71-
type: String,
72-
alias: ["c", "cfg"],
73-
description: "配置文件路径",
74-
},
75-
76-
format: {
77-
type: String,
78-
alias: ["f", "fmt"],
79-
description: "输出格式",
80-
},
81-
},
82-
})
83-
.on("config", (ctx) => {
84-
// 所有这些都可以工作:
85-
// $ node cli.mjs config --config file.json
86-
// $ node cli.mjs config -c file.json
87-
// $ node cli.mjs config -cfg file.json
88-
// $ node cli.mjs config --format json
89-
// $ node cli.mjs config -f json
90-
// $ node cli.mjs config -fmt json
91-
})
92-
.parse();
93-
```
94-
95-
### 组合短别名
67+
### 组合短名称
9668

97-
使用短别名(单个字符)时,它们可以组合在一起:
69+
使用短名称(单个字符)时,它们可以组合在一起:
9870

9971
```ts
10072
const cli = Cli()
10173
.command("compress", "压缩文件", {
10274
flags: {
10375
output: {
10476
type: String,
105-
alias: "o",
77+
short: "o",
10678
description: "输出文件",
10779
},
10880

10981
verbose: {
11082
type: Boolean,
111-
alias: "v",
83+
short: "v",
11284
description: "详细输出",
11385
},
11486

11587
recursive: {
11688
type: Boolean,
117-
alias: "r",
89+
short: "r",
11890
description: "递归模式",
11991
},
12092
},

docs/zh/guide/types.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const cli = Cli()
3333

3434
message: {
3535
type: String,
36-
alias: "m",
36+
short: "m",
3737
description: "问候信息",
3838
},
3939
},
@@ -66,7 +66,7 @@ const cli = Cli()
6666

6767
watch: {
6868
type: Boolean,
69-
alias: "w",
69+
short: "w",
7070
description: "启用监视模式",
7171
},
7272
},
@@ -135,14 +135,14 @@ const cli = Cli()
135135
// 使用 [String] 来接受多个字符串值
136136
include: {
137137
type: [String],
138-
alias: "i",
138+
short: "i",
139139
description: "包含的文件模式",
140140
},
141141

142142
// 使用 [Number] 来接受多个数字值
143143
ports: {
144144
type: [Number],
145-
alias: "p",
145+
short: "p",
146146
description: "要监听的端口",
147147
},
148148
},
@@ -172,7 +172,7 @@ const cli = Cli()
172172
// [Boolean] 类型会计数选项被使用的次数
173173
verbose: {
174174
type: [Boolean],
175-
alias: "v",
175+
short: "v",
176176
description: "详细日志级别(-v, -vv, -vvv)",
177177
},
178178
},
@@ -205,7 +205,7 @@ const cli = Cli()
205205
flags: {
206206
define: {
207207
type: Object,
208-
alias: "d",
208+
short: "d",
209209
description: "定义环境变量",
210210
},
211211
},
@@ -467,7 +467,7 @@ const cli = Cli()
467467
// 使用 [CommaSeparatedList] 来接受多个逗号分隔的列表
468468
patterns: {
469469
type: [CommaSeparatedList],
470-
alias: "p",
470+
short: "p",
471471
description: "文件模式(逗号分隔)",
472472
},
473473
},

0 commit comments

Comments
 (0)