Skip to content

Commit 20dfb5c

Browse files
committed
minor #13168 [Console] Documented the Command::SUCCESS and Command::FAILURE constants (javiereguiluz)
This PR was squashed before being merged into the master branch (closes #13168). Discussion ---------- [Console] Documented the Command::SUCCESS and Command::FAILURE constants Fixes #13004. Commits ------- 38ac257 [Console] Documented the Command::SUCCESS and Command::FAILURE constants
2 parents 0b049a6 + 38ac257 commit 20dfb5c

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

console.rst

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
5468
Configuring 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

155169
Now, 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

248262
Now, 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

console/lockable_trait.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ that adds two convenient methods to lock and release commands::
2727
if (!$this->lock()) {
2828
$output->writeln('The command is already running in another process.');
2929

30-
return 0;
30+
return Command::SUCCESS;
3131
}
3232

3333
// If you prefer to wait until the lock is released, use this:
@@ -41,4 +41,8 @@ that adds two convenient methods to lock and release commands::
4141
}
4242
}
4343

44+
.. versionadded:: 5.1
45+
46+
The ``Command::SUCCESS`` constant was introduced in Symfony 5.1.
47+
4448
.. _`locks`: https://en.wikipedia.org/wiki/Lock_(computer_science)

0 commit comments

Comments
 (0)