@@ -46,6 +46,8 @@ want a command to create a user::
46
46
protected function execute(InputInterface $input, OutputInterface $output)
47
47
{
48
48
// ...
49
+
50
+ return 0;
49
51
}
50
52
}
51
53
@@ -146,6 +148,8 @@ the console::
146
148
// outputs a message without adding a "\n" at the end of the line
147
149
$output->write('You are about to ');
148
150
$output->write('create a user.');
151
+
152
+ return 0;
149
153
}
150
154
151
155
Now, try executing the command:
@@ -195,6 +199,8 @@ which returns an instance of
195
199
// (this example deletes the last two lines of the section)
196
200
$section1->clear(2);
197
201
// Output is now completely empty!
202
+
203
+ return 0;
198
204
}
199
205
}
200
206
@@ -235,6 +241,8 @@ Use input options or arguments to pass information to the command::
235
241
236
242
// retrieve the argument value using getArgument()
237
243
$output->writeln('Username: '.$input->getArgument('username'));
244
+
245
+ return 0;
238
246
}
239
247
240
248
Now, you can pass the username to the command:
@@ -284,6 +292,8 @@ as a service, you can use normal dependency injection. Imagine you have a
284
292
$this->userManager->create($input->getArgument('username'));
285
293
286
294
$output->writeln('User successfully generated!');
295
+
296
+ return 0;
287
297
}
288
298
}
289
299
@@ -307,7 +317,8 @@ command:
307
317
308
318
:method: `Symfony\\ Component\\ Console\\ Command\\ Command::execute ` *(required) *
309
319
This method is executed after ``interact() `` and ``initialize() ``.
310
- It contains the logic you want the command to execute.
320
+ It contains the logic you want the command to execute and it must
321
+ return an integer which will be used as the command `exit status `_.
311
322
312
323
.. _console-testing-commands :
313
324
@@ -387,3 +398,5 @@ tools capable of helping you with different tasks:
387
398
* :doc: `/components/console/helpers/formatterhelper `: customize the output colorization
388
399
* :doc: `/components/console/helpers/progressbar `: shows a progress bar
389
400
* :doc: `/components/console/helpers/table `: displays tabular data as a table
401
+
402
+ .. _`exit status` : https://en.wikipedia.org/wiki/Exit_status
0 commit comments