You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/flags.md
+16-44Lines changed: 16 additions & 44 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,31 +19,31 @@ It's recommended to use camelCase for flag names as it will be interpreted as pa
19
19
20
20
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.
21
21
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.
23
23
24
24
All provided information will be used to generate better help documentation.
25
25
26
-
## Flag Aliases
26
+
## Flag Short Names
27
27
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.
29
29
30
-
### Single Alias
30
+
### Defining Short Names
31
31
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:
33
33
34
34
```ts
35
35
const cli =Cli()
36
36
.command("build", "Build the project", {
37
37
flags: {
38
38
output: {
39
39
type: String,
40
-
alias: "o",
40
+
short: "o",
41
41
description: "Output directory",
42
42
},
43
43
44
44
verbose: {
45
45
type: Boolean,
46
-
alias: "v",
46
+
short: "v",
47
47
description: "Enable verbose output",
48
48
},
49
49
},
@@ -59,62 +59,34 @@ const cli = Cli()
59
59
.parse();
60
60
```
61
61
62
-
### Multiple Aliases
62
+
### Validation Rules
63
63
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
65
66
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
96
68
97
-
When using short aliases (single characters), they can be combined together:
69
+
When using short names (single characters), they can be combined together:
98
70
99
71
```ts
100
72
const cli =Cli()
101
73
.command("compress", "Compress files", {
102
74
flags: {
103
75
output: {
104
76
type: String,
105
-
alias: "o",
77
+
short: "o",
106
78
description: "Output file",
107
79
},
108
80
109
81
verbose: {
110
82
type: Boolean,
111
-
alias: "v",
83
+
short: "v",
112
84
description: "Verbose output",
113
85
},
114
86
115
87
recursive: {
116
88
type: Boolean,
117
-
alias: "r",
89
+
short: "r",
118
90
description: "Recursive mode",
119
91
},
120
92
},
@@ -153,7 +125,7 @@ const cli = Cli()
153
125
someNumber: {
154
126
// Wrap the type function in an array to allow multiple values
0 commit comments