@@ -129,8 +129,15 @@ public function runCompletion()
129129 */
130130 protected function completeForOptions ()
131131 {
132- if ($ this ->command && strpos ($ this ->words [$ this ->wordIndex ], '- ' ) === 0 ) {
133- return $ this ->formatOptions ($ this ->command );
132+ $ word = $ this ->words [$ this ->wordIndex ];
133+ if ($ this ->command && strpos ($ word , '- ' ) === 0 ) {
134+ $ options = array ();
135+
136+ foreach ($ this ->getAllOptions () as $ opt ) {
137+ $ options [] = '-- ' .$ opt ->getName ();
138+ }
139+
140+ return $ options ;
134141 }
135142 }
136143
@@ -148,36 +155,6 @@ protected function completeForOptionShortcuts()
148155 }
149156 }
150157
151- /**
152- * Complete long-form option values
153- * @return array
154- */
155- protected function completeForOptionValues ()
156- {
157-
158- // fwrite(STDERR, "\n".print_r($this->words, true)."\n\nIndex: $this->wordIndex\n\n");
159-
160- // if ($this->command && $this->wordIndex > 1) {
161- // $left = $this->words[$this->wordIndex-1];
162- //
163- // // Complete short options
164- // if (strpos($left, '--') === 0) {
165- //
166- // $name = substr($left, 2);
167- // $def = $this->command->getDefinition();
168- //
169- // if (!$def->hasOption($name)) {
170- // return false;
171- // }
172- //
173- // $opt = $def->getOption($name);
174- // if ($opt->isValueRequired() || $opt->isValueOptional()) {
175- // return $this->completeOption($opt);
176- // }
177- // }
178- // }
179- }
180-
181158 /**
182159 * @return mixed
183160 */
@@ -206,6 +183,33 @@ protected function completeForOptionShortcutValues()
206183 return false ;
207184 }
208185
186+ /**
187+ * @return mixed
188+ */
189+ protected function completeForOptionValues ()
190+ {
191+ if ($ this ->command && $ this ->wordIndex > 1 ) {
192+ $ left = $ this ->words [$ this ->wordIndex -1 ];
193+
194+ if (strpos ($ left , '-- ' ) === 0 ) {
195+
196+ $ name = substr ($ left , 2 );
197+ $ def = $ this ->command ->getDefinition ();
198+
199+ if (!$ def ->hasOption ($ name )) {
200+ return false ;
201+ }
202+
203+ $ opt = $ def ->getOption ($ name );
204+ if ($ opt ->isValueRequired () || $ opt ->isValueOptional ()) {
205+ return $ this ->completeOption ($ opt );
206+ }
207+ }
208+ }
209+
210+ return false ;
211+ }
212+
209213 /**
210214 * If a command is not set, list available commands
211215 * @return array
@@ -252,28 +256,6 @@ public function getInput()
252256 return new ArrayInput ($ words );
253257 }
254258
255- /**
256- * @return array
257- */
258- protected function formatOptions ()
259- {
260- $ options = array ();
261- foreach ($ this ->getAllOptions () as $ opt ) {
262- $ string = '-- ' .$ opt ->getName ();
263-
264- if ($ opt ->isValueRequired ()) {
265- $ options [] = $ string .'= \\" \\" ' ;
266- } else if ($ opt ->isValueOptional ()) {
267- $ options [] = $ string ;
268- $ options [] = $ string .'= \\" \\" ' ;
269- } else {
270- $ options [] = $ string ;
271- }
272-
273- }
274- return $ options ;
275- }
276-
277259 /**
278260 * @param BaseCommand $cmd
279261 * @return bool|mixed
0 commit comments