@@ -45,12 +45,26 @@ want a command to create a user::
4545
4646 protected function execute(InputInterface $input, OutputInterface $output)
4747 {
48- // ...
48+ // ... put here the code to run in your command
49+
50+ // this method must return an integer number with the "exit status code"
51+ // of the command. You can also use these constants to make code more readable
52+
53+ // return this if there was no problem running the command
54+ // (it's equivalent to returning int(0))
55+ return Command::SUCCESS;
4956
50- return 0;
57+ // or return this if some error happened during the execution
58+ // (it's equivalent to returning int(1))
59+ // return Command::FAILURE;
5160 }
5261 }
5362
63+ .. versionadded :: 5.1
64+
65+ The ``Command::SUCCESS `` and ``Command::FAILURE `` constants were introduced
66+ in Symfony 5.1.
67+
5468Configuring the Command
5569-----------------------
5670
@@ -149,7 +163,7 @@ the console::
149163 $output->write('You are about to ');
150164 $output->write('create a user.');
151165
152- return 0 ;
166+ return Command::SUCCESS ;
153167 }
154168
155169Now, try executing the command:
@@ -200,7 +214,7 @@ which returns an instance of
200214 $section1->clear(2);
201215 // Output is now completely empty!
202216
203- return 0 ;
217+ return Command::SUCCESS ;
204218 }
205219 }
206220
@@ -242,7 +256,7 @@ Use input options or arguments to pass information to the command::
242256 // retrieve the argument value using getArgument()
243257 $output->writeln('Username: '.$input->getArgument('username'));
244258
245- return 0 ;
259+ return Command::SUCCESS ;
246260 }
247261
248262Now, you can pass the username to the command:
@@ -293,7 +307,7 @@ as a service, you can use normal dependency injection. Imagine you have a
293307
294308 $output->writeln('User successfully generated!');
295309
296- return 0 ;
310+ return Command::SUCCESS ;
297311 }
298312 }
299313
0 commit comments