Skip to content

Commit d6962af

Browse files
authored
Add mandatory exit status
Modified all execute() functions and added a note with the new requirement which links to an explanation of exit statuses.
1 parent ec8b84b commit d6962af

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

console.rst

Lines changed: 13 additions & 0 deletions
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

@@ -308,6 +318,7 @@ command:
308318
:method:`Symfony\\Component\\Console\\Command\\Command::execute` *(required)*
309319
This method is executed after ``interact()`` and ``initialize()``.
310320
It contains the logic you want the command to execute.
321+
Must 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)