File tree 2 files changed +19
-8
lines changed
2 files changed +19
-8
lines changed Original file line number Diff line number Diff line change @@ -35,18 +35,23 @@ public function __construct(array $args = null, $ignoreFirst = true)
35
35
*/
36
36
// 1 - Fixed <name> capturing group so it handles hyphens.
37
37
preg_match_all (
38
- '@(?:-{1,2}|\/)(?<name>[\w-]+)(?:[=:]? |\s+)(?<value>[^-\s"][^"]*?|" [^"]*")?(?=\s+[-/]|$) @i ' ,
38
+ '@(?:-{1,2}|\/)(?<name>[\w-]+)(?:(?:[:=] |\s+)(?:(? <value>[^-\s"][^"\s]+)|(?:"(?<value_in_quotes> [^"]+?)")))? @i ' ,
39
39
$ string ,
40
40
$ matches ,
41
41
PREG_SET_ORDER
42
42
);
43
43
44
44
foreach ($ matches as $ arg ) {
45
45
$ name = $ arg ['name ' ];
46
- $ value = isset ($ arg ['value ' ])
47
- ? $ arg ['value ' ]
48
- : true
49
- ;
46
+
47
+ $ value = true ;
48
+ if (isset ($ arg ['value_in_quotes ' ])) {
49
+ $ value = $ arg ['value_in_quotes ' ];
50
+
51
+ } elseif (isset ($ arg ['value ' ])) {
52
+ $ value = $ arg ['value ' ];
53
+ }
54
+
50
55
$ this ->args [] = new CLILib \Argument ($ name , $ value );
51
56
$ this ->keys [] = $ name ;
52
57
}
Original file line number Diff line number Diff line change @@ -16,19 +16,25 @@ public function testValidPassArgsToConstructor()
16
16
'--database myDB ' ,
17
17
'-h:local:host ' ,
18
18
'--lots-of-hyphens ' ,
19
- '--with-hyphen=alrighty ' ,
19
+ '--with-hyphen="alrighty" ' ,
20
+ '-j /var/path/to/some_interesting_file.json ' ,
21
+ '-x "/var/path/to/some/otherfile.xml" '
20
22
], false );
21
23
22
- $ this ->assertEquals (7 , iterator_count ($ it ));
24
+ $ this ->assertEquals (9 , iterator_count ($ it ));
23
25
$ this ->assertTrue ($ it ->find ('hithere ' )->value ());
24
26
$ this ->assertEquals ('cheese ' , $ it ->find ('c ' )->value ());
25
27
26
28
// 1 - Added tests to check for hyphens in argument names
27
29
$ this ->assertTrue ($ it ->find ('lots-of-hyphens ' )->value ());
28
30
$ this ->assertEquals ('alrighty ' , $ it ->find ('with-hyphen ' )->value ());
29
31
32
+ $ this ->assertEquals ('/var/path/to/some_interesting_file.json ' , $ it ->find ('j ' )->value ());
33
+
34
+ $ this ->assertEquals ('/var/path/to/some/otherfile.xml ' , $ it ->find ('x ' )->value ());
35
+
30
36
// Since iterator_count() was used, the iterator position should be at the end.
31
- $ this ->assertEquals (7 , $ it ->key ());
37
+ $ this ->assertEquals (9 , $ it ->key ());
32
38
33
39
// Return to start and check the first item is "hithere" with a value of true
34
40
$ it ->rewind ();
You can’t perform that action at this time.
0 commit comments