Skip to content

Commit 7fda95c

Browse files
committed
Merge branch '5.0'
* 5.0: Add mandatory exit status Update console.rst
2 parents 3e11070 + ad75aa9 commit 7fda95c

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

console.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ want a command to create a user::
4646
protected function execute(InputInterface $input, OutputInterface $output)
4747
{
4848
// ...
49+
50+
return 0;
4951
}
5052
}
5153

@@ -146,6 +148,8 @@ the console::
146148
// outputs a message without adding a "\n" at the end of the line
147149
$output->write('You are about to ');
148150
$output->write('create a user.');
151+
152+
return 0;
149153
}
150154

151155
Now, try executing the command:
@@ -195,6 +199,8 @@ which returns an instance of
195199
// (this example deletes the last two lines of the section)
196200
$section1->clear(2);
197201
// Output is now completely empty!
202+
203+
return 0;
198204
}
199205
}
200206

@@ -235,6 +241,8 @@ Use input options or arguments to pass information to the command::
235241

236242
// retrieve the argument value using getArgument()
237243
$output->writeln('Username: '.$input->getArgument('username'));
244+
245+
return 0;
238246
}
239247

240248
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
284292
$this->userManager->create($input->getArgument('username'));
285293

286294
$output->writeln('User successfully generated!');
295+
296+
return 0;
287297
}
288298
}
289299

@@ -307,7 +317,8 @@ command:
307317

308318
:method:`Symfony\\Component\\Console\\Command\\Command::execute` *(required)*
309319
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`_.
311322

312323
.. _console-testing-commands:
313324

@@ -387,3 +398,5 @@ tools capable of helping you with different tasks:
387398
* :doc:`/components/console/helpers/formatterhelper`: customize the output colorization
388399
* :doc:`/components/console/helpers/progressbar`: shows a progress bar
389400
* :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

Comments
 (0)