File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -36,10 +36,12 @@ public function normalizeArgs(array $args): array
3636 $ normalized = [];
3737
3838 foreach ($ args as $ arg ) {
39- if (\preg_match ('/^\-\w{2,}/ ' , $ arg )) {
39+ if (\preg_match ('/^\-\w=/ ' , $ arg )) {
40+ $ normalized = \array_merge ($ normalized , explode ('= ' , $ arg ));
41+ } elseif (\preg_match ('/^\-\w{2,}/ ' , $ arg )) {
4042 $ splitArg = \implode (' - ' , \str_split (\ltrim ($ arg , '- ' )));
4143 $ normalized = \array_merge ($ normalized , \explode (' ' , '- ' . $ splitArg ));
42- } elseif (\preg_match ('/^\-\-\w{2,} \=/ ' , $ arg )) {
44+ } elseif (\preg_match ('/^\-\-([^\s\=]+) \=/ ' , $ arg )) {
4345 $ normalized = \array_merge ($ normalized , explode ('= ' , $ arg ));
4446 } else {
4547 $ normalized [] = $ arg ;
Original file line number Diff line number Diff line change @@ -185,6 +185,21 @@ public function test_user_options()
185185 $ this ->assertSame ('user ' , reset ($ o )->name ());
186186 }
187187
188+ public function test_complex_value_option ()
189+ {
190+ $ p = $ this ->newCommand ()
191+ ->option ('-l --limit ' , 'limit ' , 'intval ' )
192+ ->option ('-o --order-by ' , 'order by ' );
193+
194+ // `--order-by="id desc"` in terminal becomes `--order-by=id desc` in PHP.
195+ $ v = $ p ->parse (['cmd ' , '-l=5 ' , '--order-by=id desc ' ])->values ();
196+
197+ $ this ->assertArrayHasKey ('limit ' , $ v );
198+ $ this ->assertArrayHasKey ('orderBy ' , $ v );
199+ $ this ->assertSame (5 , $ v ['limit ' ]);
200+ $ this ->assertSame ('id desc ' , $ v ['orderBy ' ]);
201+ }
202+
188203 public function test_usage ()
189204 {
190205 $ p = $ this ->newCommand ()->usage ('Usage: $ cmd [...] ' );
You can’t perform that action at this time.
0 commit comments