Task #49016

TYPO3 Flow Base Distribution - Task #51183: CLI improvements

Use Symfony.Console for Output + Interaction in CommandController

Added by Marc Neuhaus about 6 years ago. Updated about 5 years ago.

Status:
Resolved
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2013-06-11
Due date:
% Done:

100%

Sprint:
PHP Version:
Has patch:
No
Complexity:

Description

I think we should make use of the Smfony.Console component for output and interaction. It offers anything someone writing a command might wish for:

- easy output coloring through "<error>Warning!</error>"
- TableHelper to render a formatted table
- ProgressHelper to render and advance and progress bar
- DialogHelper with numerous types of questions like: select, ask, confirm, askHidden, etc

I already tested to use it inside an ActionController yesterday, which worked quite easily.

Another thing i testet yesterday was, to ask the user for missing arguments instead of failing with "Required argument "foo" is not set.":

./flow kickstart:model              
Please specify the required argument "packageKey": My.Package
Please specify the required argument "modelName": 

This change would add a dependency for Symfony/Console, but in most cases it is there already because Doctrine depends on it.

Associated revisions

Revision 57a18f82 (diff)
Added by Marc Neuhaus about 5 years ago

[!!!][FEATURE] Integrate Symfony/Console into CommandController

This extends the base ``CommandController`` by some convenience
helpers from the ``symfony/console`` package:

  • easy output coloring through "<error>Warning!</error>"
  • TableHelper to render values to a grid
  • ProgressHelper to render and advance and progress bars
  • DialogHelper with numerous types of questions like: select,
    ask, confirm, askHidden, etc

Additionally this change improves the
``mapRequestArgumentsToControllerArguments()`` method to ask for
missing required arguments instead of quitting with an exception.

You can make use of the new features by calling the introduced
proxy methods from within your CommandController:

  • outputTable()
  • select()
  • ask()
  • askConfirmation()
  • askHiddenResponse()
  • askAndValidate()
  • askHiddenResponseAndValidate()
  • progressStart()
  • progressSet()
  • progressAdvance()
  • progressFinish()

This change does not alter the public API so it is not breaking
in the strict sense. But it introduces a new behavior:
Previously all outputs where collected in the ``Cli\Response``
and only rendered to the console at the end of a CLI request.
Now all methods producing output (inluding ``output()`` and
``outputLine()``) render the result directly to the console.

If you use ``$this->response`` directly or let the command method
return a string, the rendering is still deferred until the end of
the CLI request.

Resolves: #49016
Releases: master
Change-Id: I063742aca1898695f2e40f36b3e207248ac6e55c

Revision 7937a988 (diff)
Added by Bastian Waidelich about 5 years ago

[BUGFIX] Fix CommandController unit tests

Adjusts the ``CommandControllerTest`` to the CommandController
that has been adjusted with
I063742aca1898695f2e40f36b3e207248ac6e55c

Change-Id: I33c54bfcbd116c5fcf10688b8e01f858fdfdd6b1
Related: #49016
Releases: master

Revision 490c3067 (diff)
Added by Bastian Waidelich about 5 years ago

[BUGFIX] Re-add styling for standard tags in CLI

With the integration of ``symfony/console`` in #49016 the support for
some HTML tags was lost, namely ``<b>``, ``<i>``, ``<u>``, ``<em>``
and ``<strike>``.

This change registers these tags again in the default ConsoleOutput.

Note: In order to get the formatted output to work the ``posix`` PHP
extension is required!

Change-Id: I8f3597c3b0856fc1159c7c173c0cfebcbf2278a6
Related: #49016
Releases: master

Revision 122c134f (diff)
Added by Marc Neuhaus over 4 years ago

[FEATURE] Automatically move generated migration to package

This adds some interaction to the ``doctrine:migrationgenerate``
command allowing to move generated doctrine migrations to the
specified package.

Example output::

Do you want to move the migration to one of these Packages?
[0 ] Don't Move
[1 ] TYPO3.Fluid
[2 ] TYPO3.Eel
[3 ] TYPO3.Flow
[4 ] TYPO3.Party
...

Change-Id: I441d6e78217e0ca1425c46600b8a443c50f9e0c0
Releases: master
Related: #49016

Revision 27c9de83 (diff)
Added by Bastian Waidelich over 4 years ago

[BUGFIX] Adjust CommandLine documentation to refactored console output

This adjusts the ``CommandLine`` section of the documentation to
changes introduced with Ia77c62b41fb598bdfb7b81c530494ba819a590d1.

Change-Id: I2c0c372bd30604b235c614f6eb878563f1a4b398
Related: #49016
Releases: master, 2.3

Revision 0bb8bac7 (diff)
Added by Bastian Waidelich over 4 years ago

[BUGFIX] Adjust CommandLine documentation to refactored console output

This adjusts the ``CommandLine`` section of the documentation to
changes introduced with Ia77c62b41fb598bdfb7b81c530494ba819a590d1.

Change-Id: I2c0c372bd30604b235c614f6eb878563f1a4b398
Related: #49016
Releases: master, 2.3

History

#2 Updated by Bastian Waidelich about 6 years ago

  • Parent task set to #51183

#3 Updated by Kay Strobach almost 6 years ago

@Marc please post your example code, i'm extremly interested.

#4 Updated by Kay Strobach almost 6 years ago

That's what i found out so far:

https://gist.github.com/kaystrobach/7500128

The cleaner version would be to modify the CliResponse directly, this would also make it possible to use the progressbar and the table renderer ...
This should be possible with AOP as well -.-

#5 Updated by Kay Strobach almost 6 years ago

btw it does not make any sense for me to buffer the output of a cli request, it should be always passed directly.
the send method should be simply empty and the appendContent should directly print the content!

#6 Updated by Kay Strobach almost 6 years ago

Just updated my gist with an AOP implementation https://gist.github.com/kaystrobach/7500128

#7 Updated by Marc Neuhaus almost 6 years ago

Hey i converted My test into an abstract Controller in Famelo.Common:

https://github.com/mneuhaus/Famelo.Common/blob/master/Documentation/AbstractInteractiveCommandController.md

:-)

#8 Updated by Kay Strobach almost 6 years ago

could you make a RFC for that as patch - i would gladly review

#9 Updated by Marc Neuhaus almost 6 years ago

i don't think this will have a chance to get into master in this current form, because it completely circumvents the default TYPO3.Flow Response.

Not sure how exactly to tackle this. i'll have to talk to robert about this i guess :)

#10 Updated by Kay Strobach almost 6 years ago

there was a chat with atleast RafealK today about this problem, i will take a look on it, i think we need to implement this in CLI\Response.

#11 Updated by Stefano Kowalke about 5 years ago

Is there any updates on that topic?

#13 Updated by Gerrit Code Review about 5 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.Flow has been pushed to the review server.
It is available at https://review.typo3.org/30653

#14 Updated by Marc Neuhaus about 5 years ago

Conclusion of the technical discussion meeting (http://wiki.typo3.org/TYPO3_Neos-DiscussionMeetings):

As we already have a hard dependency to Symfony/Console we decided to extend the existing \TYPO3\Flow\Cli\CommandController to use the Symfony console internally. The API will be backwards compatible with one exception: $this->output() and $this->outputLine() will no longer buffer the output until the end of the request but render content directly to the console. This is a desired side-effect that enables features like progress bars.

#15 Updated by Gerrit Code Review about 5 years ago

Patch set 2 for branch master of project Packages/TYPO3.Flow has been pushed to the review server.
It is available at https://review.typo3.org/30653

#16 Updated by Gerrit Code Review about 5 years ago

Patch set 3 for branch master of project Packages/TYPO3.Flow has been pushed to the review server.
It is available at https://review.typo3.org/30653

#17 Updated by Gerrit Code Review about 5 years ago

Patch set 4 for branch master of project Packages/TYPO3.Flow has been pushed to the review server.
It is available at https://review.typo3.org/30653

#18 Updated by Anonymous about 5 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

Also available in: Atom PDF