@@ -140,6 +140,7 @@ module.exports = function (yargs, usage, validation) {
140140 // what does yargs look like after the buidler is run?
141141 var innerArgv = parsed . argv
142142 var innerYargs = null
143+ var positionalMap = { }
143144
144145 currentContext . commands . push ( command )
145146 if ( typeof commandHandler . builder === 'function' ) {
@@ -173,15 +174,17 @@ module.exports = function (yargs, usage, validation) {
173174 aliases = innerYargs . parsed . aliases
174175 }
175176
176- if ( ! yargs . _hasOutput ( ) ) populatePositionals ( commandHandler , innerArgv , currentContext , yargs )
177-
178- if ( commandHandler . handler && ! yargs . _hasOutput ( ) ) {
179- commandHandler . handler ( innerArgv )
177+ if ( ! yargs . _hasOutput ( ) ) {
178+ positionalMap = populatePositionals ( commandHandler , innerArgv , currentContext , yargs )
180179 }
181180
182181 // we apply validation post-hoc, so that custom
183182 // checks get passed populated positional arguments.
184- yargs . _runValidation ( innerArgv , aliases )
183+ yargs . _runValidation ( innerArgv , aliases , positionalMap )
184+
185+ if ( commandHandler . handler && ! yargs . _hasOutput ( ) ) {
186+ commandHandler . handler ( innerArgv )
187+ }
185188
186189 currentContext . commands . pop ( )
187190 numFiles = currentContext . files . length - numFiles
@@ -196,25 +199,27 @@ module.exports = function (yargs, usage, validation) {
196199 argv . _ = argv . _ . slice ( context . commands . length ) // nuke the current commands
197200 var demanded = commandHandler . demanded . slice ( 0 )
198201 var optional = commandHandler . optional . slice ( 0 )
202+ var positionalMap = { }
199203
200204 validation . positionalCount ( demanded . length , argv . _ . length )
201205
202206 while ( demanded . length ) {
203207 var demand = demanded . shift ( )
204- populatePositional ( demand , argv , yargs )
208+ populatePositional ( demand , argv , yargs , positionalMap )
205209 }
206210
207211 while ( optional . length ) {
208212 var maybe = optional . shift ( )
209- populatePositional ( maybe , argv , yargs )
213+ populatePositional ( maybe , argv , yargs , positionalMap )
210214 }
211215
212216 argv . _ = context . commands . concat ( argv . _ )
217+ return positionalMap
213218 }
214219
215220 // populate a single positional argument and its
216221 // aliases onto argv.
217- function populatePositional ( positional , argv , yargs ) {
222+ function populatePositional ( positional , argv , yargs , positionalMap ) {
218223 // "positional" consists of the positional.cmd, an array representing
219224 // the positional's name and aliases, and positional.variadic
220225 // indicating whether or not it is a variadic array.
@@ -229,6 +234,7 @@ module.exports = function (yargs, usage, validation) {
229234 if ( value ) argv [ cmd ] = value
230235 else argv [ cmd ] = value = argv . _ . shift ( )
231236 }
237+ positionalMap [ cmd ] = true
232238 postProcessPositional ( yargs , argv , cmd )
233239 addCamelCaseExpansions ( argv , cmd )
234240 }
0 commit comments