Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add documentation about hidden response method in Console helper #1822

Merged
merged 2 commits into from

4 participants

@romainneutron

this PR adds docs to symfony/symfony#5731

components/console/introduction.rst
((36 lines not shown))
+ }
+
+ $password = $dialog->askAndValidate(
+ $output,
+ 'Please enter the name of the widget',
+ $validator,
+ 20,
+ 'foo'
+ );
+
+The validation callback can be any callable PHP function, the fourth argument is
+the maximum number of attempts, set it to `false` for unlimited attempts. The
+fifth argument is the default value.
+
+.. versionadded:: 2.2
+ The ``askHiddenResponse`` method was added in Symfony 2.2.
@stof
stof added a note

This is duplicated from above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@stof stof commented on the diff
components/console/introduction.rst
((29 lines not shown))
+
+ $dialog = $this->getHelperSet()->get('dialog');
+
+ $validator = function ($value) {
+ if (trim($value) === '') {
+ throw new \Exception('The value can not be empty');
+ }
+ }
+
+ $password = $dialog->askAndValidate(
+ $output,
+ 'Please enter the name of the widget',
+ $validator,
+ 20,
+ 'foo'
+ );
@stof
stof added a note

this part is documenting a method which exists since 2.0, so you should send it as a separate PR to the 2.0 branch (and btw, we may want to organize things a bit, as mentionned in #1811)

Great, i'll do it tonight

@weaverryan Collaborator

I agree with @stof exactly. We should first make a PR against 2.0 with everything you have here except for anything that's new in 2.2. I'll then merge that in and then we can rebase this PR after that's been done.

I also agree totally with @stof in #1811, though I think we can either do that right now, or get all of this stuff added and then refactor. @romainneutron, if you're comfortable refactoring into some new sections - great :). Otherwise, we'll handle that later.

Thanks!

hello @stof , @weaverryan ,

I'm always happy to give some time, but I'm quite busy lately.
Let's refactor into some new sections :+1: !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
components/console/introduction.rst
((6 lines not shown))
+
+You can also ask question and hide the response. This is particularly
+convenient for passwords::
+
+ $dialog = $this->getHelperSet()->get('dialog');
+ $password = $dialog->askHiddenResponse(
+ $output,
+ 'What is the database password ?',
+ false
+ );
+
+.. caution::
+
+ When you ask an hidden response, Symfony will use either a binary, change
+ stty mode or use another trick to hide the response. If none is available,
+ it will fallback on the classic question unless you pass `false` as the
@WouterJ Collaborator
WouterJ added a note

You should use:

 ``false``

Instead of a single backtrick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
components/console/introduction.rst
((18 lines not shown))
+
+ When you ask an hidden response, Symfony will use either a binary, change
+ stty mode or use another trick to hide the response. If none is available,
+ it will fallback on the classic question unless you pass `false` as the
+ third argument like in the example above. In this case, a RuntimeException
+ would be thrown.
+
+Ask and validate response
+-------------------------
+
+You can easily ask question and validate response with built-in methods::
+
+ $dialog = $this->getHelperSet()->get('dialog');
+
+ $validator = function ($value) {
+ if (trim($value) === '') {
@WouterJ Collaborator
WouterJ added a note

This should be '' == trim($value)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
components/console/introduction.rst
((43 lines not shown))
+ 'foo'
+ );
+
+The validation callback can be any callable PHP function, the fourth argument is
+the maximum number of attempts, set it to `false` for unlimited attempts. The
+fifth argument is the default value.
+
+.. versionadded:: 2.2
+ The ``askHiddenResponse`` method was added in Symfony 2.2.
+
+You can also ask and validate hidden response::
+
+ $dialog = $this->getHelperSet()->get('dialog');
+
+ $validator = function ($value) {
+ if (trim($value) === '') {
@WouterJ Collaborator
WouterJ added a note

same here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@weaverryan
Collaborator

Hey Romain!

One thing we do need to do right now is make a separate PR against 2.0 with all the things except for the 2.2 new features. Are you able to do that? I can do some patching on your behalf, but I try not to make commits "on behalf" of others (but I do want you to get credit for the updates!)

Let me know - thanks!

@romainneutron

I'm gonna do this RIGHT NOW :)

@romainneutron

Is this ok @weaverryan ? Let me know whan it's merged as I will rebase this one

@weaverryan
Collaborator

@romainneutron Merged! Rebase rebase rebase :)

@romainneutron

@weaverryan you don't want to merge 2.0 in master before I rebase ?

@weaverryan
Collaborator

Hey Romain!

I'm all merged in right now - you should be ready to go now :)

Thanks!

@romainneutron

it's all done @weaverryan !

@weaverryan weaverryan merged commit d75d573 into symfony:master
@weaverryan
Collaborator

Merged - thanks so much!

@romainneutron

thank to you Ryan !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 72 additions and 2 deletions.
  1. +72 −2 components/console/introduction.rst
View
74 components/console/introduction.rst
@@ -287,6 +287,76 @@ if you needed to know the name of something, you might do the following::
'foo'
);
+.. versionadded:: 2.2
+ The ``askHiddenResponse`` method was added in Symfony 2.2.
+
+You can also ask question and hide the response. This is particularly
+convenient for passwords::
+
+ $dialog = $this->getHelperSet()->get('dialog');
+ $password = $dialog->askHiddenResponse(
+ $output,
+ 'What is the database password ?',
+ false
+ );
+
+.. caution::
+
+ When you ask an hidden response, Symfony will use either a binary, change
+ stty mode or use another trick to hide the response. If none is available,
+ it will fallback on the classic question unless you pass ``false`` as the
+ third argument like in the example above. In this case, a RuntimeException
+ would be thrown.
+
+Ask and validate response
+-------------------------
+
+You can easily ask question and validate response with built-in methods::
+
+ $dialog = $this->getHelperSet()->get('dialog');
+
+ $validator = function ($value) {
+ if (trim($value) == '') {
+ throw new \Exception('The value can not be empty');
+ }
+ }
+
+ $password = $dialog->askAndValidate(
+ $output,
+ 'Please enter the name of the widget',
+ $validator,
+ 20,
+ 'foo'
+ );
@stof
stof added a note

this part is documenting a method which exists since 2.0, so you should send it as a separate PR to the 2.0 branch (and btw, we may want to organize things a bit, as mentionned in #1811)

Great, i'll do it tonight

@weaverryan Collaborator

I agree with @stof exactly. We should first make a PR against 2.0 with everything you have here except for anything that's new in 2.2. I'll then merge that in and then we can rebase this PR after that's been done.

I also agree totally with @stof in #1811, though I think we can either do that right now, or get all of this stuff added and then refactor. @romainneutron, if you're comfortable refactoring into some new sections - great :). Otherwise, we'll handle that later.

Thanks!

hello @stof , @weaverryan ,

I'm always happy to give some time, but I'm quite busy lately.
Let's refactor into some new sections :+1: !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+The validation callback can be any callable PHP function, the fourth argument is
+the maximum number of attempts, set it to ``false`` for unlimited attempts. The
+fifth argument is the default value.
+
+.. versionadded:: 2.2
+ The ``askHiddenResponseAndValidate`` method was added in Symfony 2.2.
+
+You can also ask and validate hidden response::
+
+ $dialog = $this->getHelperSet()->get('dialog');
+
+ $validator = function ($value) {
+ if (trim($value) == '') {
+ throw new \Exception('The password can not be empty');
+ }
+ }
+
+ $password = $dialog->askHiddenResponseAndValidate(
+ $output,
+ 'Please enter the name of the widget',
+ $validator,
+ 20,
+ false
+ );
+
+If you want to fallback on classic question in case hidden response can not be
+provided, pass true as fifth argument.
+
Displaying a Progress Bar
-------------------------
@@ -310,7 +380,7 @@ pass it a total number of units, and advance the progress as your command execut
// advance the progress bar 1 unit
$progress->advance();
- }
+ }
$progress->finish();
@@ -346,7 +416,7 @@ To see other available options, check the API documentation for
to a high number. For example, if you're iterating over a large number
of items, consider a smaller "step" number that updates on only some
iterations::
-
+
$progress->start($output, 500);
$i = 0;
while ($i++ < 50000) {
Something went wrong with that request. Please try again.