-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
[RFC] The Symfony Console Style Guide #4265
Comments
I think there should always be 1 blank line before the result bar as well. |
@kbond good catch! I've just updated the PDF. |
I like the direction the styleguide wants to guide you: Making outputs more consistent and clear. However, I don't like many concrete guides in the styleguide. GeneralThe behaviour of the current help command and the behaviour of the console component in general is based on the common standard defined as the docopt standard. I don't like it if we move away from that standard, the Symfony Styleguide should only extend it imo. Specific points
Please don't take this as an attack on you. I like the time you're putting into the Symfony community and I like it that you're doing the first step on this. However, I just wanted to share my thoughts on the exact guide. (and as always, it's just my opinion, do with it whatever you like :P). |
I would like to see some additional examples for
|
What about exceptions? How should they be styled? |
@kbond thanks for noticing all these missing things. Let's do a recap here:
|
Also, what about a "Warning" result bar that would be orange or yellow? Might be useful to show "OK but with some errors" |
@kbond any existing command that you are aware of that needs that Warning result bar? I'd like to analyze the use case. Thanks. |
I can't think of any in Symfony core but I can think a use case in one of the bundles I maintain. zenstruck/cache-bundle has a command that warms up the http cache by hitting a list of urls. If all the urls return 200, I would show green, if some returned !200, I would show orange, if all returned !200 I would show red. |
I like this a lot. It will also help the community with keeping bundle commands consistent as well. I like the question styles and it should also tie in nicely with symfony/symfony#11975 which shows the default answer to the user. |
@wouterj first, it's impossible that I consider your comment as a personal attack. Everything in the Symfony community is debatable and I repeatedly asked for feedback (positive or negative). Constructive criticism is what's making us win, so keep 'em coming :) There are a lot of things in your comment, so let's break into three big parts: Quick comments
User Input in new lineThe rationale for this is showed in this illustration: Creating a new line for user input allows us to show a perfect alignment. The eye of the user doesn't jump from one point to another to scan the values he/she typed. In addition, keep in mind that questions may show the default values and the allowed values. This can produce ultra long question lines that can break user input (that's ugly and confusing): Information and debug messagesThis is the most controversial part of the style guide so far. First, I confess that it's a completely personal opinion. I haven't seen this "feature" used anywhere. Second, my rationale was like this: I like when things are self-explained. This is a title, this is an error message, this is the result of the command, etc. If this info messages don't include some distinctive design, they look like: "hey, here it is some random text. Who knows what's this? See the illustration for a visual explanation: |
I've just uploaded a new version which includes the Progress Bar styles. |
A lot of commands add or remove files. Should the style guide contain standards for displaying this? |
@kbond in my opinion:
|
@kbond it looks awful! Thanks for reporting this error. Any Linux/Mac expert knows which are the correct UTF-8 characters to use for creating good looking progress bar. |
Be careful about using UTF-8 chars for the progressbar: they won't work on Windows |
@stof I don't forget about you :) That's why we define different styles for Windows and Mac/Linux (See page 9 of the guide): |
linux and mac look uglier, can we have the windows style on mac? it feels more at home |
yeah, I saw it when reading again the updated style guide. We should make them the defaults in the ProgressBar class though, to make it easy |
@cordoval it's true that the current style guide should be improved. But I also think that the Windows style is ugly. Anyway, in the Linux world we've had beautiful progress bars since forever. That's why I'm asking for help to any Linux expert who knows what are the UTF8 chars to use. |
if it is like brew it would be nice, i think as similar as possible to the standard and beautiful would be a 👍 oh wait nah, it is ugly with ############### signs, so you are good! |
@kbond @wouterj the style guide has been updated with:
Sorry for the massive pinging, but I'd love to read the opinions (positive or negative) of the rest of Symfony Core (@webmozart, @Tobion, @romainneutron, @nicolas-grekas, @jakzal) and other heavy users of the console (@pgodel, @hhamon, @pborreli, @jderusse, @lyrixx, @xabbuh, @weaverryan, @ricardclau, @mmoreram, @raulfraile, @aferrandini): Download Symfony Console Style Guide v 0.89 (PDF, 126 KB) |
I'm not a fan of the 1 space indentation. It makes it harder to write commands, because you have to add an extra space in each place where you wrap your messages. What is the reason to ask for it ? |
For the multi-choice question, be careful that your proposal does not work everywhere. It requires running it a stty to be able to implement it. For Windows or other non-stty environments, the current way where you enter a number to choose the option will need to be kept. See symfony/symfony#11326 for the related PR |
Hi Javier, I really like the work you've done with this document. I agree with most of the propositions. They look consistent to me for the usage experience but I can't tell for the development experience as long as I need to give a try to some of them. Regarding the |
For the admonitions, should the text on lines 2+ be indented to match the first line? I saw you did this for multi-line question validation errors. |
@stof about the 1 space indent, the rationale is: this is a pure aesthetic decision. I propose to add this space because things look better (in my opinion) and it allows us to get a perfect alignment of all elements. Regarding the comment about how hard would be to write commands, thanks to these new helpers the effort should be exactly the same, because the developer would never deal with these aesthetic details. |
For the caution admonitions, exceptions and result bars, can we pad the blocks vertically. I find them too thin. |
@kbon could you please share a quick screenshot to better visualize the problem? Thanks! |
You are right, they are too thin :( The problem is that adding a 1 line padding above and bellow could be too much. What do you think? |
Adding a line above and below seems crucial to me. |
I don't think it is required for the note admonition as there is no background color. |
@kbond agree! Only when the content has a background color. |
@kbond yes. Anyway, I guess that we can do style tweaks during the stabilization phase. We'll have to check colors and revisit other controversial elements of the style guide. |
@kbond for the progress bar, can we make it of the same color as the text? (it should be displayed white in your black console, but it should be black/dark gray for users with light consoles) |
…to the current draft of the Symfony Console Style Guide (symfony/symfony-docs#4265)
Hi, Nice work, consistency between console outputs will be great for DX. |
@javiereguiluz Is there any news about this? |
@javiereguiluz Can you give a quick overview of what you think would be the next steps? As far as I understand, the guide is finished and people could start reworking all commands. Is that right? |
…(kbond) This PR was squashed before being merged into the 2.7 branch (closes #14057). Discussion ---------- [RFC][Console] Added console style guide helpers (v2) *(Rebased to 2.7)* | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #12014, #12035, symfony/symfony-docs#4265 | License | MIT | Doc PR | todo ## Proposed API ### Code ```php // Symfony command protected function execute(InputInterface $input, OutputInterface $output) { $output = new SymfonyStyle($output); $output->title('Lorem Ipsum Dolor Sit Amet'); $output->text(array( 'Duis aute irure dolor in reprehenderit in voluptate velit esse', 'cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat' )); $output->ln(); $output->table(array('Name', 'Method', 'Scheme', 'Host', 'Path'), array( array('admin_post_new', 'ANY', 'ANY', 'ANY', '/admin/post/new'), array('admin_post_show', 'GET', 'ANY', 'ANY', '/admin/post/{id}'), array('admin_post_edit', 'ANY', 'ANY', 'ANY', '/admin/post/{id}/edit'), array('admin_post_delete', 'DELETE', 'ANY', 'ANY', '/admin/post/{id}'), )); $output->caution(array( 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris.', 'foo' )); $output->section('Consectetur Adipisicing Elit Sed Do Eiusmod'); $output->listing(array( 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod, tempor incididunt ut labore et dolore magna aliqua.', 'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo.', 'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' )); $customValidator = function ($value) { if ($value == 'foo') { throw new \Exception('cannot be foo'); } return $value; }; // hidden question $output->note($output->askHidden('Hidden question')); // choice questions $output->note($output->choice('Choice question no default', array('choice1', 'choice2'))); $output->note($output->choice('Choice question with default', array('choice1', 'choice2'), 'choice1')); // confirmation questions $output->note($output->confirm('Confirmation with yes default', true) ? 'yes' : 'no'); $output->note($output->confirm('Confirmation with no default', false) ? 'yes' : 'no'); // standard questions $output->note($output->ask('Question no default')); $output->note($output->ask('Question no default and custom validator', null, $customValidator)); $output->note($output->ask('Question with default', 'default')); $output->note($output->ask('Question with default and custom validator', 'default', $customValidator)); $output->note('Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat.'); $output->success('Lorem ipsum dolor sit amet, consectetur adipisicing elit'); $output->error('Duis aute irure dolor in reprehenderit in voluptate velit esse.'); $output->warning('Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi.'); $output->progressStart(100); for ($i = 0; $i < 100; $i++) { usleep(10000); $output->progressAdvance(); } $output->progressFinish(); } ``` ### Output ``` $ php app/console command Lorem Ipsum Dolor Sit Amet ========================== // Duis aute irure dolor in reprehenderit in voluptate velit esse // cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat ------------------- -------- -------- ------ ----------------------- Name Method Scheme Host Path ------------------- -------- -------- ------ ----------------------- admin_post_new ANY ANY ANY /admin/post/new admin_post_show GET ANY ANY /admin/post/{id} admin_post_edit ANY ANY ANY /admin/post/{id}/edit admin_post_delete DELETE ANY ANY /admin/post/{id} ------------------- -------- -------- ------ ----------------------- ! [CAUTION] Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et ! dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris. Lorem ipsum dolor sit amet, ! consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim ! veniam, quis nostrud exercitation ullamco laboris. ! ! foo Consectetur Adipisicing Elit Sed Do Eiusmod ------------------------------------------- * Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod, tempor incididunt ut labore et dolore magna aliqua. * Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo. * Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Hidden question: > <f><o><o><enter> ! [NOTE] foo Choice question no default: [0] choice1 [1] choice2 > <enter> [ERROR] Value "" is invalid Choice question no default: [0] choice1 [1] choice2 > 0<enter> ! [NOTE] choice1 Choice question with default [choice1]: [0] choice1 [1] choice2 > 1<enter> ! [NOTE] choice2 Confirmation with yes default (yes/no) [yes]: > <enter> ! [NOTE] yes Confirmation with no default (yes/no) [no]: > <enter> ! [NOTE] no Question no default: > <enter> [ERROR] A value is required. Question no default: > foo<enter> ! [NOTE] foo Question no default and custom validator: > foo<enter> [ERROR] cannot be foo Question no default and custom validator: > <enter> [ERROR] A value is required. Question no default and custom validator: > foo<enter> [ERROR] cannot be foo Question no default and custom validator: > bar<enter> ! [NOTE] bar Question with default [default]: > <enter> ! [NOTE] default Question with default and custom validator [default]: > <enter> ! [NOTE] default ! [NOTE] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ! Excepteur sint occaecat cupidatat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu ! fugiat nulla pariatur. Excepteur sint occaecat cupidatat. Duis aute irure dolor in reprehenderit in voluptate velit ! esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat. [OK] Lorem ipsum dolor sit amet, consectetur adipisicing elit [ERROR] Duis aute irure dolor in reprehenderit in voluptate velit esse. [WARNING] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi. 100/100 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% ``` ### Screenshots ![screen1](https://cloud.githubusercontent.com/assets/127811/4507077/53bc009c-4b09-11e4-937c-44fe7fe30dc0.png) ![screen2](https://cloud.githubusercontent.com/assets/127811/4507078/53bf982e-4b09-11e4-8b5a-8c44c20ae4d9.png) ![screen](https://cloud.githubusercontent.com/assets/127811/6848451/b2e64848-d3a3-11e4-9916-43bd377684ca.png) Commits ------- 96b4210 [RFC][Console] Added console style guide helpers (v2)
…(kbond) This PR was squashed before being merged into the 2.7 branch (closes #14057). Discussion ---------- [RFC][Console] Added console style guide helpers (v2) *(Rebased to 2.7)* | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #12014, #12035, symfony/symfony-docs#4265 | License | MIT | Doc PR | todo ## Proposed API ### Code ```php // Symfony command protected function execute(InputInterface $input, OutputInterface $output) { $output = new SymfonyStyle($output); $output->title('Lorem Ipsum Dolor Sit Amet'); $output->text(array( 'Duis aute irure dolor in reprehenderit in voluptate velit esse', 'cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat' )); $output->ln(); $output->table(array('Name', 'Method', 'Scheme', 'Host', 'Path'), array( array('admin_post_new', 'ANY', 'ANY', 'ANY', '/admin/post/new'), array('admin_post_show', 'GET', 'ANY', 'ANY', '/admin/post/{id}'), array('admin_post_edit', 'ANY', 'ANY', 'ANY', '/admin/post/{id}/edit'), array('admin_post_delete', 'DELETE', 'ANY', 'ANY', '/admin/post/{id}'), )); $output->caution(array( 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris.', 'foo' )); $output->section('Consectetur Adipisicing Elit Sed Do Eiusmod'); $output->listing(array( 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod, tempor incididunt ut labore et dolore magna aliqua.', 'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo.', 'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.' )); $customValidator = function ($value) { if ($value == 'foo') { throw new \Exception('cannot be foo'); } return $value; }; // hidden question $output->note($output->askHidden('Hidden question')); // choice questions $output->note($output->choice('Choice question no default', array('choice1', 'choice2'))); $output->note($output->choice('Choice question with default', array('choice1', 'choice2'), 'choice1')); // confirmation questions $output->note($output->confirm('Confirmation with yes default', true) ? 'yes' : 'no'); $output->note($output->confirm('Confirmation with no default', false) ? 'yes' : 'no'); // standard questions $output->note($output->ask('Question no default')); $output->note($output->ask('Question no default and custom validator', null, $customValidator)); $output->note($output->ask('Question with default', 'default')); $output->note($output->ask('Question with default and custom validator', 'default', $customValidator)); $output->note('Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat.'); $output->success('Lorem ipsum dolor sit amet, consectetur adipisicing elit'); $output->error('Duis aute irure dolor in reprehenderit in voluptate velit esse.'); $output->warning('Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi.'); $output->progressStart(100); for ($i = 0; $i < 100; $i++) { usleep(10000); $output->progressAdvance(); } $output->progressFinish(); } ``` ### Output ``` $ php app/console command Lorem Ipsum Dolor Sit Amet ========================== // Duis aute irure dolor in reprehenderit in voluptate velit esse // cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat ------------------- -------- -------- ------ ----------------------- Name Method Scheme Host Path ------------------- -------- -------- ------ ----------------------- admin_post_new ANY ANY ANY /admin/post/new admin_post_show GET ANY ANY /admin/post/{id} admin_post_edit ANY ANY ANY /admin/post/{id}/edit admin_post_delete DELETE ANY ANY /admin/post/{id} ------------------- -------- -------- ------ ----------------------- ! [CAUTION] Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et ! dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris. Lorem ipsum dolor sit amet, ! consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim ! veniam, quis nostrud exercitation ullamco laboris. ! ! foo Consectetur Adipisicing Elit Sed Do Eiusmod ------------------------------------------- * Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod, tempor incididunt ut labore et dolore magna aliqua. * Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo. * Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Hidden question: > <f><o><o><enter> ! [NOTE] foo Choice question no default: [0] choice1 [1] choice2 > <enter> [ERROR] Value "" is invalid Choice question no default: [0] choice1 [1] choice2 > 0<enter> ! [NOTE] choice1 Choice question with default [choice1]: [0] choice1 [1] choice2 > 1<enter> ! [NOTE] choice2 Confirmation with yes default (yes/no) [yes]: > <enter> ! [NOTE] yes Confirmation with no default (yes/no) [no]: > <enter> ! [NOTE] no Question no default: > <enter> [ERROR] A value is required. Question no default: > foo<enter> ! [NOTE] foo Question no default and custom validator: > foo<enter> [ERROR] cannot be foo Question no default and custom validator: > <enter> [ERROR] A value is required. Question no default and custom validator: > foo<enter> [ERROR] cannot be foo Question no default and custom validator: > bar<enter> ! [NOTE] bar Question with default [default]: > <enter> ! [NOTE] default Question with default and custom validator [default]: > <enter> ! [NOTE] default ! [NOTE] Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ! Excepteur sint occaecat cupidatat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu ! fugiat nulla pariatur. Excepteur sint occaecat cupidatat. Duis aute irure dolor in reprehenderit in voluptate velit ! esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat. [OK] Lorem ipsum dolor sit amet, consectetur adipisicing elit [ERROR] Duis aute irure dolor in reprehenderit in voluptate velit esse. [WARNING] Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi. 100/100 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100% ``` ### Screenshots ![screen1](https://cloud.githubusercontent.com/assets/127811/4507077/53bc009c-4b09-11e4-937c-44fe7fe30dc0.png) ![screen2](https://cloud.githubusercontent.com/assets/127811/4507078/53bf982e-4b09-11e4-8b5a-8c44c20ae4d9.png) ![screen](https://cloud.githubusercontent.com/assets/127811/6848451/b2e64848-d3a3-11e4-9916-43bd377684ca.png) Commits ------- 96b4210 [RFC][Console] Added console style guide helpers (v2)
With the new styles now merged into the code and the core commands in progress of being updated, I think it's time to move this issue forward. I think the best first step is to transform the latest PDF in this issue into reStructured Text formatting in the documentation. This way, we can easily discuss the guide and improve it. |
@javiereguiluz Can you please add a link to the current (final) version of the style guide to your initial description? It would make it easier for people wanting to contribute to find the most recent version. |
We can close this as "fixed". The feature is implemented since Symfony 2.7 and the docs are published at https://symfony.com/doc/current/cookbook/console/style.html |
This is the proposal for the new Symfony Console Style Guide. Please review it as soon as you can, because the schedule is pretty tight. We'd like to update most of the commands for Symfony 2.6 version.
Download Symfony Console Style Guide (PDF, 89 KB)
The text was updated successfully, but these errors were encountered: