@@ -66,6 +66,7 @@ class Application
66
66
private $ dispatcher ;
67
67
private $ terminalDimensions ;
68
68
private $ defaultCommand ;
69
+ private $ singleCommand ;
69
70
70
71
/**
71
72
* Constructor.
@@ -167,8 +168,7 @@ public function doRun(InputInterface $input, OutputInterface $output)
167
168
$ name = $ this ->getCommandName ($ input );
168
169
if (true === $ input ->hasParameterOption (array ('--help ' , '-h ' ), true )) {
169
170
if (!$ name ) {
170
- $ name = 'help ' ;
171
- $ input = new ArrayInput (array ('command ' => 'help ' ));
171
+ $ input = new ArrayInput (array ('command_name ' => $ this ->defaultCommand ));
172
172
} else {
173
173
$ this ->wantHelps = true ;
174
174
}
@@ -226,6 +226,13 @@ public function setDefinition(InputDefinition $definition)
226
226
*/
227
227
public function getDefinition ()
228
228
{
229
+ if ($ this ->singleCommand ) {
230
+ $ inputDefinition = $ this ->definition ;
231
+ $ inputDefinition ->setArguments ();
232
+
233
+ return $ inputDefinition ;
234
+ }
235
+
229
236
return $ this ->definition ;
230
237
}
231
238
@@ -832,7 +839,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
832
839
*/
833
840
protected function getCommandName (InputInterface $ input )
834
841
{
835
- return $ input ->getFirstArgument ();
842
+ return $ this -> singleCommand ?: $ input ->getFirstArgument ();
836
843
}
837
844
838
845
/**
@@ -1017,6 +1024,22 @@ private function findAlternatives($name, $collection)
1017
1024
public function setDefaultCommand ($ commandName )
1018
1025
{
1019
1026
$ this ->defaultCommand = $ commandName ;
1027
+
1028
+ return $ this ;
1029
+ }
1030
+
1031
+ public function setSingleCommand ($ commandName )
1032
+ {
1033
+ if (null !== $ this ->singleCommand ) {
1034
+ throw new \LogicException ('A Single command is already defined. ' );
1035
+ }
1036
+
1037
+ // Ensure the command exist
1038
+ $ this ->find ($ commandName );
1039
+
1040
+ $ this ->singleCommand = $ commandName ;
1041
+
1042
+ return $ this ;
1020
1043
}
1021
1044
1022
1045
private function stringWidth ($ string )
0 commit comments