File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -259,10 +259,26 @@ public function group(string $group, callable $fn): self
259259 public function commandFor (array $ argv ): Command
260260 {
261261 $ argv += [null , null , null ];
262+ $ command = null ;
263+
264+ //sort by key length
265+ //find maximal command compatibility by arguments
266+ $ keys = array_map ('strlen ' , array_keys ($ this ->commands ));
267+ array_multisort ($ keys , SORT_ASC , $ this ->commands );
268+
269+ foreach ($ this ->commands as $ command_name => $ value ) {
270+ $ nb_args = count (explode (' ' , $ command_name ));
271+ $ args = implode (' ' , array_slice ($ argv , 1 , $ nb_args ));
272+ if (!empty ($ this ->commands [$ args ])) {
273+ $ command = $ this ->commands [$ args ];
274+ }
275+ }
262276
263277 return
278+ //cmd found by multi arguments
279+ $ command
264280 // cmd
265- $ this ->commands [$ argv [1 ]]
281+ ?? $ this ->commands [$ argv [1 ]]
266282 // cmd alias
267283 ?? $ this ->commands [$ this ->aliases [$ argv [1 ]] ?? null ]
268284 // default.
You can’t perform that action at this time.
0 commit comments