File tree 3 files changed +41
-6
lines changed
3 files changed +41
-6
lines changed Original file line number Diff line number Diff line change @@ -108,10 +108,18 @@ module.exports = (helpText, options) => {
108
108
delete argv . _ ;
109
109
110
110
const flags = camelcaseKeys ( argv , { exclude : [ '--' , / ^ \w $ / ] } ) ;
111
+ const unnormalizedFlags = { ...flags } ;
112
+
113
+ if ( options . flags !== undefined ) {
114
+ for ( const flagValue of Object . values ( options . flags ) ) {
115
+ delete flags [ flagValue . alias ] ;
116
+ }
117
+ }
111
118
112
119
return {
113
120
input,
114
121
flags,
122
+ unnormalizedFlags,
115
123
pkg,
116
124
help,
117
125
showHelp,
Original file line number Diff line number Diff line change @@ -73,7 +73,8 @@ foo(cli.input[0], cli.flags);
73
73
Returns an ` Object ` with:
74
74
75
75
- ` input ` * (Array)* - Non-flag arguments
76
- - ` flags ` * (Object)* - Flags converted to camelCase
76
+ - ` flags ` * (Object)* - Flags converted to camelCase excluding aliases
77
+ - ` unnormalizedFlags ` * (Object)* - Flags converted camelCase including aliases
77
78
- ` pkg ` * (Object)* - The ` package.json ` object
78
79
- ` help ` * (string)* - The help text used with ` --help `
79
80
- ` showHelp([code=2]) ` * (Function)* - Show the help text and exit with ` code `
@@ -229,6 +230,11 @@ const cli = meow(`
229
230
/*
230
231
{
231
232
flags: {
233
+ rainbow: true,
234
+ unicorn: false,
235
+ sparkles: true
236
+ },
237
+ unnormalizedFlags: {
232
238
rainbow: true,
233
239
r: true,
234
240
unicorn: false,
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ test('spawn cli and not show help screen', async t => {
57
57
58
58
test ( 'spawn cli and test input' , async t => {
59
59
const { stdout} = await execa ( './fixture.js' , [ '-u' , 'cat' ] ) ;
60
- t . is ( stdout , 'u\nunicorn \nmeow\ncamelCaseOption' ) ;
60
+ t . is ( stdout , 'unicorn \nmeow\ncamelCaseOption' ) ;
61
61
} ) ;
62
62
63
63
test ( 'spawn cli and test input flag' , async t => {
@@ -172,8 +172,7 @@ test('accept help and options', t => {
172
172
}
173
173
}
174
174
} ) . flags , {
175
- foo : true ,
176
- f : true
175
+ foo : true
177
176
} ) ;
178
177
} ) ;
179
178
@@ -192,9 +191,31 @@ test('grouped short-flags work', t => {
192
191
}
193
192
} ) ;
194
193
194
+ const { unnormalizedFlags} = cli ;
195
+ t . true ( unnormalizedFlags . coco ) ;
196
+ t . true ( unnormalizedFlags . loco ) ;
197
+ t . true ( unnormalizedFlags . c ) ;
198
+ t . true ( unnormalizedFlags . l ) ;
199
+ } ) ;
200
+
201
+ test ( 'grouped flags work' , t => {
202
+ const cli = meow ( {
203
+ argv : [ '-cl' ] ,
204
+ flags : {
205
+ coco : {
206
+ type : 'boolean' ,
207
+ alias : 'c'
208
+ } ,
209
+ loco : {
210
+ type : 'boolean' ,
211
+ alias : 'l'
212
+ }
213
+ }
214
+ } ) ;
215
+
195
216
const { flags} = cli ;
196
217
t . true ( flags . coco ) ;
197
218
t . true ( flags . loco ) ;
198
- t . true ( flags . c ) ;
199
- t . true ( flags . l ) ;
219
+ t . is ( flags . c , undefined ) ;
220
+ t . is ( flags . l , undefined ) ;
200
221
} ) ;
You can’t perform that action at this time.
0 commit comments