8000 symfony-docs/console.rst at 10bbee33a7f9076c069a49e005c1aad74ae15ab6 · symfony/symfony-docs · GitHub
[go: up one dir, main page]

Skip to content
{"payload":{"allShortcutsEnabled":false,"fileTree":{"":{"items":[{"name":".github","path":".github","contentType":"directory"},{"name":"_build","path":"_build","contentType":"directory"},{"name":"_images","path":"_images","contentType":"directory"},{"name":"_includes","path":"_includes","contentType":"directory"},{"name":"bundles","path":"bundles","contentType":"directory"},{"name":"components","path":"components","contentType":"directory"},{"name":"configuration","path":"configuration","contentType":"directory"},{"name":"console","path":"console","contentType":"directory"},{"name":"contributing","path":"contributing","contentType":"directory"},{"name":"controller","path":"controller","contentType":"directory"},{"name":"create_framework","path":"create_framework","contentType":"directory"},{"name":"deployment","path":"deployment","contentType":"directory"},{"name":"doctrine","path":"doctrine","contentType":"directory"},{"name":"form","path":"form","contentType":"directory"},{"name":"frontend","path":"frontend","contentType":"directory"},{"name":"getting_started","path":"getting_started","contentType":"directory"},{"name":"http_cache","path":"http_cache","contentType":"directory"},{"name":"introduction","path":"introduction","contentType":"directory"},{"name":"logging","path":"logging","contentType":"directory"},{"name":"messenger","path":"messenger","contentType":"directory"},{"name":"quick_tour","path":"quick_tour","contentType":"directory"},{"name":"reference","path":"reference","contentType":"directory"},{"name":"routing","path":"routing","contentType":"directory"},{"name":"security","path":"security","contentType":"directory"},{"name":"serializer","path":"serializer","contentType":"directory"},{"name":"service_container","path":"service_container","contentType":"directory"},{"name":"setup","path":"setup","contentType":"directory"},{"name":"testing","path":"testing","contentType":"directory"},{"name":"validation","path":"validation","contentType":"directory"},{"name":"workflow","path":"workflow","contentType":"directory"},{"name":".alexrc","path":".alexrc","contentType":"file"},{"name":".doctor-rst.yaml","path":".doctor-rst.yaml","contentType":"file"},{"name":".editorconfig","path":".editorconfig","contentType":"file"},{"name":".gitignore","path":".gitignore","contentType":"file"},{"name":"LICENSE.md","path":"LICENSE.md","contentType":"file"},{"name":"README.md","path":"README.md","contentType":"file"},{"name":"best_practices.rst","path":"best_practices.rst","contentType":"file"},{"name":"bundles.rst","path":"bundles.rst","contentType":"file"},{"name":"cache.rst","path":"cache.rst","contentType":"file"},{"name":"configuration.rst","path":"configuration.rst","contentType":"file"},{"name":"console.rst","path":"console.rst","contentType":"file"},{"name":"controller.rst","path":"controller.rst","contentType":"file"},{"name":"deployment.rst","path":"deployment.rst","contentType":"file"},{"name":"doctrine.rst","path":"doctrine.rst","contentType":"file"},{"name":"event_dispatcher.rst","path":"event_dispatcher.rst","contentType":"file"},{"name":"forms.rst","path":"forms.rst","contentType":"file"},{"name":"frontend.rst","path":"frontend.rst","contentType":"file"},{"name":"html_sanitizer.rst","path":"html_sanitizer.rst","contentType":"file"},{"name":"http_cache.rst","path":"http_cache.rst","contentType":"file"},{"name":"http_client.rst","path":"http_client.rst","contentType":"file"},{"name":"index.rst","path":"index.rst","contentType":"file"},{"name":"lock.rst","path":"lock.rst","contentType":"file"},{"name":"logging.rst","path":"logging.rst","contentType":"file"},{"name":"mailer.rst","path":"mailer.rst","contentType":"file"},{"name":"mercure.rst","path":"mercure.rst","contentType":"file"},{"name":"messenger.rst","path":"messenger.rst","contentType":"file"},{"name":"migration.rst","path":"migration.rst","contentType":"file"},{"name":"notifier.rst","path":"notifier.rst","contentType":"file"},{"name":"page_creation.rst","path":"page_creation.rst","contentType":"file"},{"name":"performance.rst","path":"performance.rst","contentType":"file"},{"name":"profiler.rst","path":"profiler.rst","contentType":"file"},{"name":"rate_limiter.rst","path":"rate_limiter.rst","contentType":"file"},{"name":"routing.rst","path":"routing.rst","contentType":"file"},{"name":"scheduler.rst","path":"scheduler.rst","contentType":"file"},{"name":"security.rst","path":"security.rst","contentType":"file"},{"name":"serializer.rst","path":"serializer.rst","contentType":"file"},{"name":"service_container.rst","path":"service_container.rst","contentType":"file"},{"name":"session.rst","path":"session.rst","contentType":"file"},{"name":"setup.rst","path":"setup.rst","contentType":"file"},{"name":"templates.rst","path":"templates.rst","contentType":"file"},{"name":"testing.rst","path":"testing.rst","contentType":"file"},{"name":"translation.rst","path":"translation.rst","contentType":"file"},{"name":"validation.rst","path":"validation.rst","contentType":"file"},{"name":"web_link.rst","path":"web_link.rst","contentType":"file"},{"name":"webhook.rst","path":"webhook.rst","contentType":"file"},{"name":"workflow.rst","path":"workflow.rst","contentType":"file"}],"totalCount":76}},"fileTreeProcessingTime":54.481102,"foldersToFetch":[],"incompleteFileTree":false,"repo":{"id":521583,"defaultBranch":"7.3","name":"symfony-docs","ownerLogin":"symfony","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2010-02-17T08:43:51.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/143937?v=4","public":true,"private":false,"isOrgOwned":true},"codeLineWrapEnabled":false,"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"10bbee33a7f9076c069a49e005c1aad74ae15ab6","listCacheKey":"v0:1748857018.0","canEdit":false,"refType":"tree","currentOid":"10bbee33a7f9076c069a49e005c1aad74ae15ab6"},"path":"console.rst","currentUser":null,"blob":{"rawLines":null,"stylingDirectives":null,"colorizedLines":null,"csv":null,"csvError":null,"dependabotInfo":{"showConfigurationBanner":false,"configFilePath":null,"networkDependabotPath":"/symfony/symfony-docs/network/updates","dismissConfigurationNoticePath":"/settings/dismiss-notice/dependabot_configuration_notice","configurationNoticeDismissed":null},"displayName":"console.rst","displayUrl":"https://github.com/symfony/symfony-docs/blob/10bbee33a7f9076c069a49e005c1aad74ae15ab6/console.rst?raw=true","headerInfo":{"blobSize":"22.9 KB","deleteTooltip":"You must be signed in to make or propose changes","editTooltip":"You must be signed in to make or propose changes","ghDesktopPath":null,"isGitLfs":false,"onBranch":false,"shortPath":"82bafd4","siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2Fsymfony%2Fsymfony-docs%2Fblob%2F10bbee33a7f9076c069a49e005c1aad74ae15ab6%2Fconsole.rst","isCSV":false,"isRichtext":true,"toc":[{"level":1,"text":"Console Commands","anchor":"console-commands","htmlText":"Console Commands"},{"level":2,"text":"Running Commands","anchor":"running-commands","htmlText":"Running Commands"},{"level":3,"text":"APP_ENV \u0026 APP_DEBUG","anchor":"app_env--app_debug","htmlText":"APP_ENV \u0026amp; APP_DEBUG"},{"level":3,"text":"Console Completion","anchor":"console-completion","htmlText":"Console Completion"},{"level":2,"text":"Creating a Command","anchor":"creating-a-command","htmlText":"Creating a Command"},{"level":3,"text":"Configuring the Command","anchor":"configuring-the-command","htmlText":"Configuring the Command"},{"level":3,"text":"Registering the Command","anchor":"registering-the-command","htmlText":"Registering the Command"},{"level":3,"text":"Running the Command","anchor":"running-the-command","htmlText":"Running the Command"},{"level":2,"text":"Console Output","anchor":"console-output","htmlText":"Console Output"},{"level":3,"text":"Output Sections","anchor":"output-sections","htmlText":"Output Sections"},{"level":2,"text":"Console Input","anchor":"console-input","htmlText":"Console Input"},{"level":2,"text":"Getting Services from the Service Container","anchor":"getting-services-from-the-service-container","htmlText":"Getting Services from the Service Container"},{"level":2,"text":"Command Lifecycle","anchor":"command-lifecycle","htmlText":"Command Lifecycle"},{"level":2,"text":"Testing Commands","anchor":"testing-commands","htmlText":"Testing Commands"},{"level":2,"text":"Logging Command Errors","anchor":"logging-command-errors","htmlText":"Logging Command Errors"},{"level":2,"text":"Using Events And Handling Signals","anchor":"using-events-and-handling-signals","htmlText":"Using Events And Handling Signals"},{"level":2,"text":"Profiling Commands","anchor":"profiling-commands","htmlText":"Profiling Commands"},{"level":2,"text":"Learn More","anchor":"learn-more","htmlText":"Learn More"}],"lineInfo":{"truncatedLoc":"685","truncatedSloc":"497"},"mode":"file"},"image":false,"isCodeownersFile":null,"isPlain":false,"isValidLegacyIssueTemplate":false,"issueTemplate":null,"discussionTemplate":null,"language":"reStructuredText","languageID":419,"large":false,"planSupportInfo":{"repoIsFork":null,"repoOwnedByCurrentUser":null,"requestFullPath":"/symfony/symfony-docs/blob/10bbee33a7f9076c069a49e005c1aad74ae15ab6/console.rst","showFreeOrgGatedFeatureMessage":null,"showPlanSupportBanner":null,"upgradeDataAttributes":null,"upgradePath":null},"publishBannersInfo":{"dismissActionNoticePath":"/settings/dismiss-notice/publish_action_from_dockerfile","releasePath":"/symfony/symfony-docs/releases/new?marketplace=true","showPublishActionBanner":false},"rawBlobUrl":"https://github.com/symfony/symfony-docs/raw/10bbee33a7f9076c069a49e005c1aad74ae15ab6/console.rst","renderImageOrRaw":false,"richText":"\u003carticle class=\"markdown-body entry-content container-lg\" itemprop=\"text\"\u003e\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch1 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eConsole Commands\u003c/h1\u003e\u003ca id=\"user-content-console-commands\" class=\"anchor\" aria-label=\"Permalink: Console Commands\" href=\"#console-commands\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eThe Symfony framework provides lots of commands through the \u003ccode\u003ebin/console\u003c/code\u003e script\n(e.g. the well-known \u003ccode\u003ebin/console cache:clear\u003c/code\u003e command). These commands are\ncreated with the \u003ca href=\"#id1\"\u003e\u003cspan id=\"user-content-id2\"\u003e:doc:`Console component \u0026lt;/components/console\u0026gt;`\u003c/span\u003e\u003c/a\u003e. You can also\nuse it to create your own commands.\u003c/p\u003e\n\u003ca name=\"user-content-running-commands\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eRunning Commands\u003c/h2\u003e\u003ca id=\"user-content-running-commands\" class=\"anchor\" aria-label=\"Permalink: Running Commands\" href=\"#running-commands\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eEach Symfony application comes with a large set of commands. You can use\nthe \u003ccode\u003elist\u003c/code\u003e command to view all available commands in the application:\u003c/p\u003e\n\u003cpre lang=\"terminal\"\u003e$ php bin/console list\n...\n\nAvailable commands:\n about Display information about the current project\n completion Dump the shell completion script\n help Display help for a command\n list List commands\n assets\n assets:install Install bundle's web assets under a public directory\n cache\n cache:clear Clear the cache\n...\n\u003c/pre\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eNote\u003c/p\u003e\n\u003cp dir=\"auto\"\u003e\u003ccode\u003elist\u003c/code\u003e is the default command, so running \u003ccode\u003ephp bin/console\u003c/code\u003e is the same.\u003c/p\u003e\n\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eIf you find the command you need, you can run it with the \u003ccode\u003e--help\u003c/code\u003e option\nto view the command's documentation:\u003c/p\u003e\n\u003cpre lang=\"terminal\"\u003e$ php bin/console assets:install --help\n\u003c/pre\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eNote\u003c/p\u003e\n\u003cp dir=\"auto\"\u003e\u003ccode\u003e--help\u003c/code\u003e is one of the built-in global options from the Console component,\nwhich are available for all commands, including those you can create.\nTo learn more about them, you can read\n\u003ca href=\"#id3\"\u003e\u003cspan id=\"user-content-id4\"\u003e:ref:`this section \u0026lt;console-global-options\u0026gt;`\u003c/span\u003e\u003c/a\u003e.\u003c/p\u003e\n\u003c/div\u003e\n\u003ca name=\"user-content-app-env-app-debug\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eAPP_ENV \u0026amp; APP_DEBUG\u003c/h3\u003e\u003ca id=\"user-content-app_env--app_debug\" class=\"anchor\" aria-label=\"Permalink: APP_ENV \u0026amp; APP_DEBUG\" href=\"#app_env--app_debug\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eConsole commands run in the \u003ca href=\"#id5\"\u003e\u003cspan id=\"user-content-id6\"\u003e:ref:`environment \u0026lt;config-dot-env\u0026gt;`\u003c/span\u003e\u003c/a\u003e defined in the \u003ccode\u003eAPP_ENV\u003c/code\u003e\nvariable of the \u003ccode\u003e.env\u003c/code\u003e file, which is \u003ccode\u003edev\u003c/code\u003e by default. It also reads the \u003ccode\u003eAPP_DEBUG\u003c/code\u003e\nvalue to turn \"debug\" mode on or off (it defaults to \u003ccode\u003e1\u003c/code\u003e, which is on).\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eTo run the command in another environment or debug mode, edit the value of \u003ccode\u003eAPP_ENV\u003c/code\u003e\nand \u003ccode\u003eAPP_DEBUG\u003c/code\u003e. You can also define this env vars when running the\ncommand, for instance:\u003c/p\u003e\n\u003cpre lang=\"terminal\"\u003e# clears the cache for the prod environment\n$ APP_ENV=prod php bin/console cache:clear\n\u003c/pre\u003e\n\u003ca name=\"user-content-console-completion\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eConsole Completion\u003c/h3\u003e\u003ca id=\"user-content-console-completion\" class=\"anchor\" aria-label=\"Permalink: Console Completion\" href=\"#console-completion\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cpre\u003e.. versionadded:: 6.1\n\n Console completion for Fish was introduced in Symfony 6.1.\n\n\u003c/pre\u003e\n\u003cpre\u003e.. versionadded:: 6.2\n\n Console completion for Zsh was introduced in Symfony 6.2.\n\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eIf you are using the Bash, Zsh or Fish shell, you can install Symfony's\ncompletion script to get auto completion when typing commands in the\nterminal. All commands support name and option completion, and some can\neven complete values.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003e\u003ca target=\"_blank\" rel=\"noopener noreferrer\" href=\"/symfony/symfony-docs/blob/10bbee33a7f9076c069a49e005c1aad74ae15ab6/_images/components/console/completion.gif\"\u003e\u003cimg alt=\"The terminal completes the command name \u0026quot;secrets:remove\u0026quot; and the argument \u0026quot;SOME_OTHER_SECRET\u0026quot;.\" src=\"/symfony/symfony-docs/raw/10bbee33a7f9076c069a49e005c1aad74ae15ab6/_images/components/console/completion.gif\" data-animated-image=\"\" style=\"max-width: 100%;\"\u003e\u003c/a\u003e\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eFirst, you have to install the completion script \u003cem\u003eonce\u003c/em\u003e. Run\n\u003ccode\u003ebin/console completion --help\u003c/code\u003e for the installation instructions for\nyour shell.\u003c/p\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eNote\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eWhen using Bash, make sure you installed and setup the \"bash completion\"\npackage for your OS (typically named \u003ccode\u003ebash-completion\u003c/code\u003e).\u003c/p\u003e\n\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eAfter installing and restarting your terminal, you're all set to use\ncompletion (by default, by pressing the Tab key).\u003c/p\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eTip\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eMany PHP tools are built using the Symfony Console component (e.g.\nComposer, PHPstan and Behat). If they are using version 5.4 or higher,\nyou can also install their completion script to enable console completion:\u003c/p\u003e\n\u003cpre lang=\"terminal\"\u003e$ php vendor/bin/phpstan completion --help\n$ composer completion --help\n\u003c/pre\u003e\n\u003c/div\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eTip\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eIf you are using the \u003ca href=\"#id7\"\u003e\u003cspan id=\"user-content-id8\"\u003e:doc:`Symfony local web server\n\u0026lt;/setup/symfony_server\u0026gt;`\u003c/span\u003e\u003c/a\u003e, it is recommended to use the built-in completion\nscript that will ensure the right PHP version and configuration are used when\nrunning the Console Completion. Run \u003ccode\u003esymfony completion --help\u003c/code\u003e for the\ninstallation instructions for your shell. The Symfony CLI will provide\ncompletion for the \u003ccode\u003econsole\u003c/code\u003e and \u003ccode\u003ecomposer\u003c/code\u003e commands.\u003c/p\u003e\n\u003c/div\u003e\n\u003ca name=\"user-content-creating-a-command\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eCreating a Command\u003c/h2\u003e\u003ca id=\"user-content-creating-a-command\" class=\"anchor\" aria-label=\"Permalink: Creating a Command\" href=\"#creating-a-command\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eCommands are defined in classes extending\n\u003ca href=\"#id9\"\u003e\u003cspan id=\"user-content-id10\"\u003e:class:`Symfony\\\\Component\\\\Console\\\\Command\\\\Command`\u003c/span\u003e\u003c/a\u003e. For example, you may\nwant a command to create a user:\u003c/p\u003e\n\u003cpre\u003e// src/Command/CreateUserCommand.php\nnamespace App\\Command;\n\nuse Symfony\\Component\\Console\\Attribute\\AsCommand;\nuse Symfony\\Component\\Console\\Command\\Command;\nuse Symfony\\Component\\Console\\Input\\InputInterface;\nuse Symfony\\Component\\Console\\Output\\OutputInterface;\n\n// the name of the command is what users type after \"php bin/console\"\n#[AsCommand(name: 'app:create-user')]\nclass CreateUserCommand extends Command\n{\n protected function execute(InputInterface $input, OutputInterface $output): int\n {\n // ... put here the code to create the user\n\n // this method must return an integer number with the \"exit status code\"\n // of the command. You can also use these constants to make code more readable\n\n // return this if there was no problem running the command\n // (it's equivalent to returning int(0))\n return Command::SUCCESS;\n\n // or return this if some error happened during the execution\n // (it's equivalent to returning int(1))\n // return Command::FAILURE;\n\n // or return this to indicate incorrect command usage; e.g. invalid options\n // or missing arguments (it's equivalent to returning int(2))\n // return Command::INVALID\n }\n}\n\u003c/pre\u003e\n\u003ca name=\"user-content-configuring-the-command\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eConfiguring the Command\u003c/h3\u003e\u003ca id=\"user-content-configuring-the-command\" class=\"anchor\" aria-label=\"Permalink: Configuring the Command\" href=\"#configuring-the-command\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eYou can optionally define a description, help message and the\n\u003ca href=\"#id11\"\u003e\u003cspan id=\"user-content-id12\"\u003e:doc:`input options and arguments \u0026lt;/console/input\u0026gt;`\u003c/span\u003e\u003c/a\u003e by overriding the\n\u003ccode\u003econfigure()\u003c/code\u003e method:\u003c/p\u003e\n\u003cpre\u003e// src/Command/CreateUserCommand.php\n\n// ...\nclass CreateUserCommand extends Command\n{\n // the command description shown when running \"php bin/console list\"\n protected static $defaultDescription = 'Creates a new user.';\n\n // ...\n protected function configure(): void\n {\n $this\n // the command help shown when running the command with the \"--help\" option\n -\u0026gt;setHelp('This command allows you to create a user...')\n ;\n }\n}\n\u003c/pre\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eTip\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eDefining the \u003ccode\u003e$defaultDescription\u003c/code\u003e static property instead of using the\n\u003ccode\u003esetDescription()\u003c/code\u003e method allows to get the command description without\ninstantiating its class. This makes the \u003ccode\u003ephp bin/console list\u003c/code\u003e command run\nmuch faster.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eIf you want to always run the \u003ccode\u003elist\u003c/code\u003e command fast, add the \u003ccode\u003e--short\u003c/code\u003e option\nto it (\u003ccode\u003ephp bin/console list --short\u003c/code\u003e). This will avoid instantiating command\nclasses, but it won't show any description for commands that use the\n\u003ccode\u003esetDescription()\u003c/code\u003e method instead of the static property.\u003c/p\u003e\n\u003c/div\u003e\n\u003cpre\u003e.. deprecated:: 6.1\n\n The static property ``$defaultDescription`` was deprecated in Symfony 6.1.\n Instead, use the ``#[AsCommand]`` attribute to define the optional command\n description.\n\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eThe \u003ccode\u003econfigure()\u003c/code\u003e method is called automatically at the end of the command\nconstructor. If your command defines its own constructor, set the properties\nfirst and then call to the parent constructor, to make those properties\navailable in the \u003ccode\u003econfigure()\u003c/code\u003e method:\u003c/p\u003e\n\u003cpre\u003e// ...\nuse Symfony\\Component\\Console\\Command\\Command;\nuse Symfony\\Component\\Console\\Input\\InputArgument;\n\nclass CreateUserCommand extends Command\n{\n // ...\n\n public function __construct(bool $requirePassword = false)\n {\n // best practices recommend to call the parent constructor first and\n // then set your own properties. That wouldn't work in this case\n // because configure() needs the properties set in this constructor\n $this-\u0026gt;requirePassword = $requirePassword;\n\n parent::__construct();\n }\n\n protected function configure(): void\n {\n $this\n // ...\n -\u0026gt;addArgument('password', $this-\u0026gt;requirePassword ? InputArgument::REQUIRED : InputArgument::OPTIONAL, 'User password')\n ;\n }\n}\n\u003c/pre\u003e\n\u003ca name=\"user-content-registering-the-command\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eRegistering the Command\u003c/h3\u003e\u003ca id=\"user-content-registering-the-command\" class=\"anchor\" aria-label=\"Permalink: Registering the Command\" href=\"#registering-the-command\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eYou can register the command by adding the \u003ccode\u003eAsCommand\u003c/code\u003e attribute to it:\u003c/p\u003e\n\u003cpre\u003e// src/Command/CreateUserCommand.php\nnamespace App\\Command;\n\nuse Symfony\\Component\\Console\\Attribute\\AsCommand;\nuse Symfony\\Component\\Console\\Command\\Command;\n\n// the \"name\" and \"description\" arguments of AsCommand replace the\n// static $defaultName and $defaultDescription properties\n#[AsCommand(\n name: 'app:create-user',\n description: 'Creates a new user.',\n hidden: false,\n aliases: ['app:add-user']\n)]\nclass CreateUserCommand extends Command\n{\n // ...\n}\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eIf you can't use PHP attributes, register the command as a service and\n\u003ca href=\"#id13\"\u003e\u003cspan id=\"user-content-id14\"\u003e:doc:`tag it \u0026lt;/service_container/tags\u0026gt;`\u003c/span\u003e\u003c/a\u003e with the \u003ccode\u003econsole.command\u003c/code\u003e tag. If you're using the\n\u003ca href=\"#id15\"\u003e\u003cspan id=\"user-content-id16\"\u003e:ref:`default services.yaml configuration \u0026lt;service-container-services-load-example\u0026gt;`\u003c/span\u003e\u003c/a\u003e,\nthis is already done for you, thanks to \u003ca href=\"#id17\"\u003e\u003cspan id=\"user-content-id18\"\u003e:ref:`autoconfiguration \u0026lt;services-autoconfigure\u0026gt;`\u003c/span\u003e\u003c/a\u003e.\u003c/p\u003e\n\u003cpre\u003e.. deprecated:: 6.1\n\n The static property ``$defaultName`` was deprecated in Symfony 6.1.\n Define your command name with the ``#[AsCommand]`` attribute instead.\n\n\u003c/pre\u003e\n\u003ca name=\"user-content-running-the-command\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eRunning the Command\u003c/h3\u003e\u003ca id=\"user-content-running-the-command\" class=\"anchor\" aria-label=\"Permalink: Running the Command\" href=\"#running-the-command\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eAfter configuring and registering the command, you can run it in the terminal:\u003c/p\u003e\n\u003cpre lang=\"terminal\"\u003e$ php bin/console app:create-user\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eAs you might expect, this command will do nothing as you didn't write any logic\nyet. Add your own logic inside the \u003ccode\u003eexecute()\u003c/code\u003e method.\u003c/p\u003e\n\u003ca name=\"user-content-console-output\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eConsole Output\u003c/h2\u003e\u003ca id=\"user-content-console-output\" class=\"anchor\" aria-label=\"Permalink: Console Output\" href=\"#console-output\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 8000 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eThe \u003ccode\u003eexecute()\u003c/code\u003e method has access to the output stream to write messages to\nthe console:\u003c/p\u003e\n\u003cpre\u003e// ...\nprotected function execute(InputInterface $input, OutputInterface $output): int\n{\n // outputs multiple lines to the console (adding \"\\n\" at the end of each line)\n $output-\u0026gt;writeln([\n 'User Creator',\n '============',\n '',\n ]);\n\n // the value returned by someMethod() can be an iterator (https://php.net/iterator)\n // that generates and returns the messages with the 'yield' PHP keyword\n $output-\u0026gt;writeln($this-\u0026gt;someMethod());\n\n // outputs a message followed by a \"\\n\"\n $output-\u0026gt;writeln('Whoa!');\n\n // outputs a message without adding a \"\\n\" at the end of the line\n $output-\u0026gt;write('You are about to ');\n $output-\u0026gt;write('create a user.');\n\n return Command::SUCCESS;\n}\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eNow, try executing the command:\u003c/p\u003e\n\u003cpre lang=\"terminal\"\u003e$ php bin/console app:create-user\nUser Creator\n============\n\nWhoa!\nYou are about to create a user.\n\u003c/pre\u003e\n\u003ca name=\"user-content-output-sections\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch3 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eOutput Sections\u003c/h3\u003e\u003ca id=\"user-content-output-sections\" class=\"anchor\" aria-label=\"Permalink: Output Sections\" href=\"#output-sections\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eThe regular console output can be divided into multiple independent regions\ncalled \"output sections\". Create one or more of these sections when you need to\nclear and overwrite the output information.\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eSections are created with the\n\u003ca href=\"#id19\"\u003e\u003cspan id=\"user-content-id20\"\u003e:method:`ConsoleOutput::section() \u0026lt;Symfony\\\\Component\\\\Console\\\\Output\\\\ConsoleOutput::section\u0026gt;`\u003c/span\u003e\u003c/a\u003e\nmethod, which returns an instance of\n\u003ca href=\"#id21\"\u003e\u003cspan id=\"user-content-id22\"\u003e:class:`Symfony\\\\Component\\\\Console\\\\Output\\\\ConsoleSectionOutput`\u003c/span\u003e\u003c/a\u003e:\u003c/p\u003e\n\u003cpre\u003e// ...\nuse Symfony\\Component\\Console\\Output\\ConsoleOutputInterface;\n\nclass MyCommand extends Command\n{\n protected function execute(InputInterface $input, OutputInterface $output): int\n {\n if (!$output instanceof ConsoleOutputInterface) {\n throw new \\LogicException('This command accepts only an instance of \"ConsoleOutputInterface\".');\n }\n\n $section1 = $output-\u0026gt;section();\n $section2 = $output-\u0026gt;section();\n\n $section1-\u0026gt;writeln('Hello');\n $section2-\u0026gt;writeln('World!');\n sleep(1);\n // Output displays \"Hello\\nWorld!\\n\"\n\n // overwrite() replaces all the existing section contents with the given content\n $section1-\u0026gt;overwrite('Goodbye');\n sleep(1);\n // Output now displays \"Goodbye\\nWorld!\\n\"\n\n // clear() deletes all the section contents...\n $section2-\u0026gt;clear();\n sleep(1);\n // Output now displays \"Goodbye\\n\"\n\n // ...but you can also delete a given number of lines\n // (this example deletes the last two lines of the section)\n $section1-\u0026gt;clear(2);\n sleep(1);\n // Output is now completely empty!\n\n // setting the max height of a section will make new lines replace the old ones\n $section1-\u0026gt;setMaxHeight(2);\n $section1-\u0026gt;writeln('Line1');\n $section1-\u0026gt;writeln('Line2');\n $section1-\u0026gt;writeln('Line3');\n\n return Command::SUCCESS;\n }\n}\n\u003c/pre\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eNote\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eA new line is appended automatically when displaying information in a section.\u003c/p\u003e\n\u003c/div\u003e\n\u003cpre\u003e.. versionadded:: 6.2\n\n The feature to limit the height of a console section was introduced in Symfony 6.2.\n\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eOutput sections let you manipulate the Console output in advanced ways, such as\n\u003ca href=\"#id23\"\u003e\u003cspan id=\"user-content-id24\"\u003e:ref:`displaying multiple progress bars \u0026lt;console-multiple-progress-bars\u0026gt;`\u003c/span\u003e\u003c/a\u003e which\nare updated independently and \u003ca href=\"#id25\"\u003e\u003cspan id=\"user-content-id26\"\u003e:ref:`appending rows to tables \u0026lt;console-modify-rendered-tables\u0026gt;`\u003c/span\u003e\u003c/a\u003e\nthat have already been rendered.\u003c/p\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eWarning\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eTerminals only allow overwriting the visible content, so you must take into\naccount the console height when trying to write/overwrite section contents.\u003c/p\u003e\n\u003c/div\u003e\n\u003ca name=\"user-content-console-input\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eConsole Input\u003c/h2\u003e\u003ca id=\"user-content-console-input\" class=\"anchor\" aria-label=\"Permalink: Console Input\" href=\"#console-input\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eUse input options or arguments to pass information to the command:\u003c/p\u003e\n\u003cpre\u003euse Symfony\\Component\\Console\\Input\\InputArgument;\n\n// ...\nprotected function configure(): void\n{\n $this\n // configure an argument\n -\u0026gt;addArgument('username', InputArgument::REQUIRED, 'The username of the user.')\n // ...\n ;\n}\n\n// ...\npublic function execute(InputInterface $input, OutputInterface $output): int\n{\n $output-\u0026gt;writeln([\n 'User Creator',\n '============',\n '',\n ]);\n\n // retrieve the argument value using getArgument()\n $output-\u0026gt;writeln('Username: '.$input-\u0026gt;getArgument('username'));\n\n return Command::SUCCESS;\n}\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eNow, you can pass the username to the command:\u003c/p\u003e\n\u003cpre lang=\"terminal\"\u003e$ php bin/console app:create-user Wouter\nUser Creator\n============\n\nUsername: Wouter\n\u003c/pre\u003e\n\u003cpre\u003e.. seealso::\n\n Read :doc:`/console/input` for more information about console options and\n arguments.\n\n\u003c/pre\u003e\n\u003ca name=\"user-content-getting-services-from-the-service-container\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eGetting Services from the Service Container\u003c/h2\u003e\u003ca id=\"user-content-getting-services-from-the-service-container\" class=\"anchor\" aria-label=\"Permalink: Getting Services from the Service Container\" href=\"#getting-services-from-the-service-container\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eTo actually create a new user, the command has to access some\n\u003ca href=\"#id27\"\u003e\u003cspan id=\"user-content-id28\"\u003e:doc:`services \u0026lt;/service_container\u0026gt;`\u003c/span\u003e\u003c/a\u003e. Since your command is already registered\nas a service, you can use normal dependency injection. Imagine you have a\n\u003ccode\u003eApp\\Service\\UserManager\u003c/code\u003e service that you want to access:\u003c/p\u003e\n\u003cpre\u003e// ...\nuse App\\Service\\UserManager;\nuse Symfony\\Component\\Console\\Command\\Command;\n\nclass CreateUserCommand extends Command\n{\n public function __construct(\n private UserManager $userManager,\n ){\n parent::__construct();\n }\n\n // ...\n\n protected function execute(InputInterface $input, OutputInterface $output): int\n {\n // ...\n\n $this-\u0026gt;userManager-\u0026gt;create($input-\u0026gt;getArgument('username'));\n\n $output-\u0026gt;writeln('User successfully generated!');\n\n return Command::SUCCESS;\n }\n}\n\u003c/pre\u003e\n\u003ca name=\"user-content-command-lifecycle\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eCommand Lifecycle\u003c/h2\u003e\u003ca id=\"user-content-command-lifecycle\" class=\"anchor\" aria-label=\"Permalink: Command Lifecycle\" href=\"#command-lifecycle\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eCommands have three lifecycle methods that are invoked when running the\ncommand:\u003c/p\u003e\n\u003cdl\u003e\n\u003cdt\u003e\u003ca href=\"#id29\"\u003e\u003cspan id=\"user-content-id30\"\u003e:method:`Symfony\\\\Component\\\\Console\\\\Command\\\\Command::initialize`\u003c/span\u003e\u003c/a\u003e \u003cem\u003e(optional)\u003c/em\u003e\u003c/dt\u003e\n\u003cdd\u003eThis method is executed before the \u003ccode\u003einteract()\u003c/code\u003e and the \u003ccode\u003eexecute()\u003c/code\u003e\nmethods. Its main purpose is to initialize variables used in the rest of\nthe command methods.\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#id31\"\u003e\u003cspan id=\"user-content-id32\"\u003e:method:`Symfony\\\\Component\\\\Console\\\\Command\\\\Command::interact`\u003c/span\u003e\u003c/a\u003e \u003cem\u003e(optional)\u003c/em\u003e\u003c/dt\u003e\n\u003cdd\u003eThis method is executed after \u003ccode\u003einitialize()\u003c/code\u003e and before \u003ccode\u003eexecute()\u003c/code\u003e.\nIts purpose is to check if some of the options/arguments are missing\nand interactively ask the user for those values. This is the last place\nwhere you can ask for missing required options/arguments. This method is\ncalled before validating the input.\nNote that it will not be called when the command is run without interaction\n(e.g. when passing the \u003ccode\u003e--no-interaction\u003c/code\u003e global option flag).\u003c/dd\u003e\n\u003cdt\u003e\u003ca href=\"#id33\"\u003e\u003cspan id=\"user-content-id34\"\u003e:method:`Symfony\\\\Component\\\\Console\\\\Command\\\\Command::execute`\u003c/span\u003e\u003c/a\u003e \u003cem\u003e(required)\u003c/em\u003e\u003c/dt\u003e\n\u003cdd\u003eThis method is executed after \u003ccode\u003einteract()\u003c/code\u003e and \u003ccode\u003einitialize()\u003c/code\u003e.\nIt contains the logic you want the command to execute and it must\nreturn an integer which will be used as the command \u003ca href=\"https://en.wikipedia.org/wiki/Exit_status\" rel=\"nofollow\"\u003eexit status\u003c/a\u003e.\u003c/dd\u003e\n\u003c/dl\u003e\n\u003ca name=\"user-content-testing-commands\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eTesting Commands\u003c/h2\u003e\u003ca id=\"user-content-testing-commands\" class=\"anchor\" aria-label=\"Permalink: Testing Commands\" href=\"#testing-commands\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eSymfony provides several tools to help you test your commands. The most\nuseful one is the \u003ca href=\"#id35\"\u003e\u003cspan id=\"user-content-id36\"\u003e:class:`Symfony\\\\Component\\\\Console\\\\Tester\\\\CommandTester`\u003c/span\u003e\u003c/a\u003e\nclass. It uses special input and output classes to ease testing without a real\nconsole:\u003c/p\u003e\n\u003cpre\u003e// tests/Command/CreateUserCommandTest.php\nnamespace App\\Tests\\Command;\n\nuse Symfony\\Bundle\\FrameworkBundle\\Console\\Application;\nuse Symfony\\Bundle\\FrameworkBundle\\Test\\KernelTestCase;\nuse Symfony\\Component\\Console\\Tester\\CommandTester;\n\nclass CreateUserCommandTest extends KernelTestCase\n{\n public function testExecute(): void\n {\n self::bootKernel();\n $application = new Application(self::$kernel);\n\n $command = $application-\u0026gt;find('app:create-user');\n $commandTester = new CommandTester($command);\n $commandTester-\u0026gt;execute([\n // pass arguments to the helper\n 'username' =\u0026gt; 'Wouter',\n\n // prefix the key with two dashes when passing options,\n // e.g: '--some-option' =\u0026gt; 'option_value',\n // use brackets for testing array value,\n // e.g: '--some-option' =\u0026gt; ['option_value'],\n ]);\n\n $commandTester-\u0026gt;assertCommandIsSuccessful();\n\n // the output of the command in the console\n $output = $commandTester-\u0026gt;getDisplay();\n $this-\u0026gt;assertStringContainsString('Username: Wouter', $output);\n\n // ...\n }\n}\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eIf you are using a \u003ca href=\"#id37\"\u003e\u003cspan id=\"user-content-id38\"\u003e:doc:`single-command application \u0026lt;/components/console/single_command_tool\u0026gt;`\u003c/span\u003e\u003c/a\u003e,\ncall \u003ccode\u003esetAutoExit(false)\u003c/code\u003e on it to get the command result in \u003ccode\u003eCommandTester\u003c/code\u003e.\u003c/p\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eTip\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eYou can also test a whole console application by using\n\u003ca href=\"#id39\"\u003e\u003cspan id=\"user-content-id40\"\u003e:class:`Symfony\\\\Component\\\\Console\\\\Tester\\\\ApplicationTester`\u003c/span\u003e\u003c/a\u003e.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eWarning\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eWhen testing commands using the \u003ccode\u003eCommandTester\u003c/code\u003e class, console events are\nnot dispatched. If you need to test those events, use the\n\u003ca href=\"#id41\"\u003e\u003cspan id=\"user-content-id42\"\u003e:class:`Symfony\\\\Component\\\\Console\\\\Tester\\\\ApplicationTester`\u003c/span\u003e\u003c/a\u003e instead.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eWarning\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eWhen testing commands using the \u003ca href=\"#id43\"\u003e\u003cspan id=\"user-content-id44\"\u003e:class:`Symfony\\\\Component\\\\Console\\\\Tester\\\\ApplicationTester`\u003c/span\u003e\u003c/a\u003e\nclass, don't forget to disable the auto exit flag:\u003c/p\u003e\n\u003cpre\u003e$application = new Application();\n$application-\u0026gt;setAutoExit(false);\n\n$tester = new ApplicationTester($application);\n\u003c/pre\u003e\n\u003c/div\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eWarning\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eWhen testing \u003ccode\u003eInputOption::VALUE_NONE\u003c/code\u003e command options, you must pass \u003ccode\u003etrue\u003c/code\u003e\nto them:\u003c/p\u003e\n\u003cpre\u003e$commandTester = new CommandTester($command);\n$commandTester-\u0026gt;execute(['--some-option' =\u0026gt; true]);\n\u003c/pre\u003e\n\u003c/div\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eNote\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eWhen using the Console component in a standalone project, use\n\u003ca href=\"#id45\"\u003e\u003cspan id=\"user-content-id46\"\u003e:class:`Symfony\\\\Component\\\\Console\\\\Application`\u003c/span\u003e\u003c/a\u003e\nand extend the normal \u003ccode\u003e\\PHPUnit\\Framework\\TestCase\u003c/code\u003e.\u003c/p\u003e\n\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eWhen testing your commands, it could be useful to understand how your command\nreacts on different settings like the width and the height of the terminal, or\neven the color mode being used. You have access to such information thanks to the\n\u003ca href=\"#id47\"\u003e\u003cspan id=\"user-content-id48\"\u003e:class:`Symfony\\\\Component\\\\Console\\\\Terminal`\u003c/span\u003e\u003c/a\u003e class:\u003c/p\u003e\n\u003cpre\u003euse Symfony\\Component\\Console\\Terminal;\n\n$terminal = new Terminal();\n\n// gets the number of lines available\n$height = $terminal-\u0026gt;getHeight();\n\n// gets the number of columns available\n$width = $terminal-\u0026gt;getWidth();\n\n// gets the color mode\n$colorMode = $terminal-\u0026gt;getColorMode();\n\n// changes the color mode\n$colorMode = $terminal-\u0026gt;setColorMode(AnsiColorMode::Ansi24);\n\u003c/pre\u003e\n\u003cpre\u003e.. versionadded:: 6.2\n\n The support for setting and getting the current color mode was introduced\n in Symfony 6.2.\n\n\u003c/pre\u003e\n\u003ca name=\"user-content-logging-command-errors\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eLogging Command Errors\u003c/h2\u003e\u003ca id=\"user-content-logging-command-errors\" class=\"anchor\" aria-label=\"Permalink: Logging Command Errors\" href=\"#logging-command-errors\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eWhenever an exception is thrown while running commands, Symfony adds a log\nmessage for it including the entire failing command. In addition, Symfony\nregisters an \u003ca href=\"#id49\"\u003e\u003cspan id=\"user-content-id50\"\u003e:doc:`event subscriber \u0026lt;/event_dispatcher\u0026gt;`\u003c/span\u003e\u003c/a\u003e to listen to the\n\u003ca href=\"#id51\"\u003e\u003cspan id=\"user-content-id52\"\u003e:ref:`ConsoleEvents::TERMINATE event \u0026lt;console-events-terminate\u0026gt;`\u003c/span\u003e\u003c/a\u003e and adds a log\nmessage whenever a command doesn't finish with the \u003ccode\u003e0\u003c/code\u003e \u003ca href=\"https://en.wikipedia.org/wiki/Exit_status\" rel=\"nofollow\"\u003eexit status\u003c/a\u003e.\u003c/p\u003e\n\u003ca name=\"user-content-using-events-and-handling-signals\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eUsing Events And Handling Signals\u003c/h2\u003e\u003ca id=\"user-content-using-events-and-handling-signals\" class=\"anchor\" aria-label=\"Permalink: Using Events And Handling Signals\" href=\"#using-events-and-handling-signals\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eWhen a command is running, many events are dispatched, one of them allows to\nreact to signals, read more in \u003ca href=\"#id53\"\u003e\u003cspan id=\"user-content-id54\"\u003e:doc:`this section \u0026lt;/components/console/events\u0026gt;`\u003c/span\u003e\u003c/a\u003e.\u003c/p\u003e\n\u003ca name=\"user-content-profiling-commands\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eProfiling Commands\u003c/h2\u003e\u003ca id=\"user-content-profiling-commands\" class=\"anchor\" aria-label=\"Permalink: Profiling Commands\" href=\"#profiling-commands\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cp dir=\"auto\"\u003eSymfony allows to profile the execution of any command, including yours. First,\nmake sure that the \u003ca href=\"#id55\"\u003e\u003cspan id=\"user-content-id56\"\u003e:ref:`debug mode \u0026lt;debug-mode\u0026gt;`\u003c/span\u003e\u003c/a\u003e and the \u003ca href=\"#id57\"\u003e\u003cspan id=\"user-content-id58\"\u003e:doc:`profiler \u0026lt;/profiler\u0026gt;`\u003c/span\u003e\u003c/a\u003e\nare enabled. Then, add the \u003ccode\u003e--profile\u003c/code\u003e option when running the command:\u003c/p\u003e\n\u003cpre lang=\"terminal\"\u003e$ php bin/console --profile app:my-command\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eSymfony will now collect data about the command execution, which is helpful to\ndebug errors or check other issues. When the command execution is over, the\nprofile is accessible through the web page of the profiler.\u003c/p\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eTip\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eIf you run the command in verbose mode (adding the \u003ccode\u003e-v\u003c/code\u003e option), Symfony\nwill display in the output a clickable link to the command profile (if your\nterminal supports links). If you run it in debug verbosity (\u003ccode\u003e-vvv\u003c/code\u003e) you'll\nalso see the time and memory consumed by the command.\u003c/p\u003e\n\u003c/div\u003e\n\u003cdiv dir=\"auto\"\u003e\n\u003cp dir=\"auto\"\u003eWarning\u003c/p\u003e\n\u003cp dir=\"auto\"\u003eWhen profiling the \u003ccode\u003emessenger:consume\u003c/code\u003e command from the \u003ca href=\"#id59\"\u003e\u003cspan id=\"user-content-id60\"\u003e:doc:`Messenger \u0026lt;/messenger\u0026gt;`\u003c/span\u003e\u003c/a\u003e\ncomponent, add the \u003ccode\u003e--no-reset\u003c/code\u003e option to the command or you won't get any\nprofile. Moreover, consider using the \u003ccode\u003e--limit\u003c/code\u003e option to only process a few\nmessages to make the profile more readable in the profiler.\u003c/p\u003e\n\u003c/div\u003e\n\u003cpre\u003e.. versionadded:: 6.4\n\n The ``--profile`` option was introduced in Symfony 6.4.\n\n\u003c/pre\u003e\n\u003ca name=\"user-content-learn-more\"\u003e\u003c/a\u003e\n\u003cdiv class=\"markdown-heading\" dir=\"auto\"\u003e\u003ch2 tabindex=\"-1\" class=\"heading-element\" dir=\"auto\"\u003eLearn More\u003c/h2\u003e\u003ca id=\"user-content-learn-more\" class=\"anchor\" aria-label=\"Permalink: Learn More\" href=\"#learn-more\"\u003e\u003csvg class=\"octicon octicon-link\" viewBox=\"0 0 16 16\" version=\"1.1\" width=\"16\" height=\"16\" aria-hidden=\"true\"\u003e\u003cpath d=\"m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z\"\u003e\u003c/path\u003e\u003c/svg\u003e\u003c/a\u003e\u003c/div\u003e\n\u003cpre\u003e.. toctree::\n :maxdepth: 1\n :glob:\n\n console/*\n\n\u003c/pre\u003e\n\u003cp dir=\"auto\"\u003eThe console component also contains a set of \"helpers\" - different small\ntools capable of helping you with different tasks:\u003c/p\u003e\n\u003cul dir=\"auto\"\u003e\n\u003cli\u003e\u003ca href=\"#id61\"\u003e\u003cspan id=\"user-content-id62\"\u003e:doc:`/components/console/helpers/questionhelper`\u003c/span\u003e\u003c/a\u003e: interactively ask the user for information\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#id63\"\u003e\u003cspan id=\"user-content-id64\"\u003e:doc:`/components/console/helpers/formatterhelper`\u003c/span\u003e\u003c/a\u003e: customize the output colorization\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#id65\"\u003e\u003cspan id=\"user-content-id66\"\u003e:doc:`/components/console/helpers/progressbar`\u003c/span\u003e\u003c/a\u003e: shows a progress bar\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#id67\"\u003e\u003cspan id=\"user-content-id68\"\u003e:doc:`/components/console/helpers/progressindicator`\u003c/span\u003e\u003c/a\u003e: shows a progress indicator\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#id69\"\u003e\u003cspan id=\"user-content-id70\"\u003e:doc:`/components/console/helpers/table`\u003c/span\u003e\u003c/a\u003e: displays tabular data as a table\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#id71\"\u003e\u003cspan id=\"user-content-id72\"\u003e:doc:`/components/console/helpers/debug_formatter`\u003c/span\u003e\u003c/a\u003e: provides functions to\noutput debug information when running an external program\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#id73\"\u003e\u003cspan id=\"user-content-id74\"\u003e:doc:`/components/console/helpers/processhelper`\u003c/span\u003e\u003c/a\u003e: allows to run processes using \u003ccode\u003eDebugFormatterHelper\u003c/code\u003e\u003c/li\u003e\n\u003cli\u003e\u003ca href=\"#id75\"\u003e\u003cspan id=\"user-content-id76\"\u003e:doc:`/components/console/helpers/cursor`\u003c/span\u003e\u003c/a\u003e: allows to manipulate the cursor in the terminal\u003c/li\u003e\n\u003c/ul\u003e\n\n\u003c/article\u003e","renderedFileInfo":null,"shortPath":null,"symbolsEnabled":true,"tabSize":4,"topBannersInfo":{"overridingGlobalFundingFile":false,"globalPreferredFundingPath":"/symfony/.github/blob/6f2ca452c856184a28812bb364b4e34ed50309da/FUNDING.yml","showInvalidCitationWarning":false,"citationHelpUrl":"https://docs.github.com/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files","actionsOnboardingTip":null},"truncated":false,"viewable":true,"workflowRedirectUrl":null,"symbols":null},"copilotInfo":null,"copilotAccessAllowed":false,"modelsAccessAllowed":false,"modelsRepoIntegrationEnabled":false,"csrf_tokens":{"/symfony/symfony-docs/branches":{"post":"kIiN2dqL85f79W5EQDr7-f0ED9Nk1YGyX62YJv-48Ce8S0R1qUKMz_pHQL7921lGtxaCkB5Ilme8nrIbsJZJSw"},"/repos/preferences":{"post":"7H16G_5RfV2zkoU8DK4-i_ndqc-UsKwIupnOQwwz7rIsJT8hOB6QX34ZHmeUKOxasnIVW2S-hiZbi2voeg7eYw"}}},"title":"symfony-docs/console.rst at 10bbee33a7f9076c069a49e005c1aad74ae15ab6 · symfony/symfony-docs","appPayload":{"helpUrl":"https://docs.github.com","findFileWorkerPath":"/assets-cdn/worker/find-file-worker-263cab1760dd.js","findInFileWorkerPath":"/assets-cdn/worker/find-in-file-worker-1b17b3e7786a.js","githubDevUrl":null,"enabled_features":{"code_nav_ui_events":false,"react_blob_overlay":false,"accessible_code_button":true}}}
0