File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -259,10 +259,25 @@ public function group(string $group, callable $fn): self
259259 public function commandFor (array $ argv ): Command
260260 {
261261 $ argv += [null , null , null ];
262-
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+ }
263276 return
277+ //cmd found by multi arguments
278+ $ command
264279 // cmd
265- $ this ->commands [$ argv [1 ]]
280+ ?? $ this ->commands [$ argv [1 ]]
266281 // cmd alias
267282 ?? $ this ->commands [$ this ->aliases [$ argv [1 ]] ?? null ]
268283 // default.
You can’t perform that action at this time.
0 commit comments