Skip to content

Fixing some line lengths in console examples to avoid horizontal scrolli... #1768

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
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
55 changes: 46 additions & 9 deletions components/console/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,17 @@ and add the following to it::
$this
->setName('demo:greet')
->setDescription('Greet someone')
->addArgument('name', InputArgument::OPTIONAL, 'Who do you want to greet?')
->addOption('yell', null, InputOption::VALUE_NONE, 'If set, the task will yell in uppercase letters')
->addArgument(
'name',
InputArgument::OPTIONAL,
'Who do you want to greet?'
)
->addOption(
'yell',
null,
InputOption::VALUE_NONE,
'If set, the task will yell in uppercase letters'
)
;
}

Expand All @@ -69,7 +78,7 @@ an ``Application`` and adds commands to it::

#!/usr/bin/env php
# app/console
<?php
<?php

use Acme\DemoBundle\Command\GreetCommand;
use Symfony\Component\Console\Application;
Expand Down Expand Up @@ -141,8 +150,16 @@ and make the ``name`` argument required::

$this
// ...
->addArgument('name', InputArgument::REQUIRED, 'Who do you want to greet?')
->addArgument('last_name', InputArgument::OPTIONAL, 'Your last name?');
->addArgument(
'name',
InputArgument::REQUIRED,
'Who do you want to greet?'
)
->addArgument(
'last_name',
InputArgument::OPTIONAL,
'Your last name?'
);

You now have access to a ``last_name`` argument in your command::

Expand Down Expand Up @@ -178,7 +195,13 @@ how many times in a row the message should be printed::

$this
// ...
->addOption('iterations', null, InputOption::VALUE_REQUIRED, 'How many times should the message be printed?', 1);
->addOption(
'iterations',
null,
InputOption::VALUE_REQUIRED,
'How many times should the message be printed?',
1
);

Next, use this in the command to print the message multiple times:

Expand Down Expand Up @@ -225,7 +248,13 @@ You can combine VALUE_IS_ARRAY with VALUE_REQUIRED or VALUE_OPTIONAL like this:

$this
// ...
->addOption('iterations', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'How many times should the message be printed?', 1);
->addOption(
'iterations',
null,
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
'How many times should the message be printed?',
1
);

Asking the User for Information
-------------------------------
Expand All @@ -236,7 +265,11 @@ to confirm an action before actually executing it. Add the following to your
command::

$dialog = $this->getHelperSet()->get('dialog');
if (!$dialog->askConfirmation($output, '<question>Continue with this action?</question>', false)) {
if (!$dialog->askConfirmation(
$output,
'<question>Continue with this action?</question>',
false
)) {
return;
}

Expand All @@ -249,7 +282,11 @@ You can also ask questions with more than a simple yes/no answer. For example,
if you needed to know the name of something, you might do the following::

$dialog = $this->getHelperSet()->get('dialog');
$name = $dialog->ask($output, 'Please enter the name of the widget', 'foo');
$name = $dialog->ask(
$output,
'Please enter the name of the widget',
'foo'
);

Testing Commands
----------------
Expand Down