Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Console] Documented the Command::SUCCESS and Command::FAILURE constants #13168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions 26 console.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,26 @@ want a command to create a user::

protected function execute(InputInterface $input, OutputInterface $output)
{
// ...
// ... put here the code to run in your command

// this method must return an integer number with the "exit status code"
// of the command. You can also use these constants to make code more readable

// return this if there was no problem running the command
// (it's equivalent to returning int(0))
return Command::SUCCESS;
javiereguiluz marked this conversation as resolved.
Show resolved Hide resolved

return 0;
// or return this if some error happened during the execution
// (it's equivalent to returning int(1))
// return Command::FAILURE;
}
}

.. versionadded:: 5.1

The ``Command::SUCCESS`` and ``Command::FAILURE`` constants were introduced
in Symfony 5.1.

Configuring the Command
-----------------------

Expand Down Expand Up @@ -149,7 +163,7 @@ the console::
$output->write('You are about to ');
$output->write('create a user.');

return 0;
return Command::SUCCESS;
}

Now, try executing the command:
Expand Down Expand Up @@ -200,7 +214,7 @@ which returns an instance of
$section1->clear(2);
// Output is now completely empty!

return 0;
return Command::SUCCESS;
}
}

Expand Down Expand Up @@ -242,7 +256,7 @@ Use input options or arguments to pass information to the command::
// retrieve the argument value using getArgument()
$output->writeln('Username: '.$input->getArgument('username'));

return 0;
return Command::SUCCESS;
}

Now, you can pass the username to the command:
Expand Down Expand Up @@ -293,7 +307,7 @@ as a service, you can use normal dependency injection. Imagine you have a

$output->writeln('User successfully generated!');

return 0;
return Command::SUCCESS;
}
}

Expand Down
6 changes: 5 additions & 1 deletion 6 console/lockable_trait.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ that adds two convenient methods to lock and release commands::
if (!$this->lock()) {
$output->writeln('The command is already running in another process.');

return 0;
return Command::SUCCESS;
}

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

.. versionadded:: 5.1

The ``Command::SUCCESS`` constant was introduced in Symfony 5.1.

.. _`locks`: https://en.wikipedia.org/wiki/Lock_(computer_science)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.