@@ -818,6 +818,35 @@ public function getCommandError($command)
818
818
return implode ("\n" , $ out );
819
819
}
820
820
821
+ /**
822
+ * Get the message output in the console stating that the option can not be found and tries to guess what the user
823
+ * wanted to say. Output a list of available options as well.
824
+ *
825
+ * @param string $option Unknown option name trying to be used.
826
+ * @return string The message to be displayed in the console.
827
+ */
828
+ public function getOptionError ($ option )
829
+ {
830
+ $ availableOptions = array_keys ($ this ->_options );
831
+ $ bestGuess = $ this ->findClosestItem ($ option , $ availableOptions );
832
+ $ out = [];
833
+ $ out [] = sprintf ('Unknown option `%s`. ' , $ option );
834
+ $ out [] = '' ;
835
+
836
+ if ($ bestGuess !== null ) {
837
+ $ out [] = sprintf ('Did you mean `%s` ? ' , $ bestGuess );
838
+ $ out [] = '' ;
839
+ }
840
+
841
+ $ out [] = 'Available options are : ' ;
842
+ $ out [] = '' ;
843
+ foreach ($ availableOptions as $ availableOption ) {
844
+ $ out [] = ' - ' . $ availableOption ;
845
+ }
846
+
847
+ return implode ("\n" , $ out );
848
+ }
849
+
821
850
/**
822
851
* Tries to guess the item name the user originally wanted using the levenshtein algorithm.
823
852
*
@@ -908,7 +937,7 @@ protected function _parseShortOption($option, $params)
908
937
protected function _parseOption ($ name , $ params )
909
938
{
910
939
if (!isset ($ this ->_options [$ name ])) {
911
- throw new ConsoleException (sprintf ( ' Unknown option `%s` ' , $ name ));
940
+ throw new ConsoleException ($ this -> getOptionError ( $ name ));
912
941
}
913
942
$ option = $ this ->_options [$ name ];
914
943
$ isBoolean = $ option ->isBoolean ();
0 commit comments