@@ -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
@@ -831,7 +838,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
831
838
*/
832
839
protected function getCommandName (InputInterface $ input )
833
840
{
834
- return $ input ->getFirstArgument ();
841
+ return $ this -> singleCommand ?: $ input ->getFirstArgument ();
835
842
}
836
843
837
844
/**
@@ -1016,6 +1023,22 @@ private function findAlternatives($name, $collection)
1016
1023
public function setDefaultCommand ($ commandName )
1017
1024
{
1018
1025
$ this ->defaultCommand = $ commandName ;
1026
+
1027
+ return $ this ;
1028
+ }
1029
+
1030
+ public function setSingleCommand ($ commandName )
1031
+ {
1032
+ if (null !== $ this ->singleCommand ) {
1033
+ throw new \LogicException ('A Single command is already defined. ' );
1034
+ }
1035
+
1036
+ // Ensure the command exist
1037
+ $ this ->find ($ commandName );
1038
+
1039
+ $ this ->singleCommand = $ commandName ;
1040
+
1041
+ return $ this ;
1019
1042
}
1020
1043
1021
1044
private function stringWidth ($ string )
0 commit comments