Skip to content

[Console] add suggestions for debug commands: firewall, form, messenger, router #43598

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 1 commit into from
Oct 30, 2021

Conversation

IonBazan
Copy link
Contributor

@IonBazan IonBazan commented Oct 20, 2021

Q A
Branch? 5.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets #43594
License MIT
Doc PR -

Adding Bash completion for following commands:

  • debug:firewall
  • debug:form
  • debug:messenger
  • debug:router

Waiting for #43596 to be merged first as it adds testing utilities and DescriptorHelper::getFormats().

@carsonbot
Copy link

Hey!

To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done?

Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review.

Cheers!

Carsonbot

@IonBazan IonBazan marked this pull request as ready for review October 20, 2021 03:53
@carsonbot carsonbot added this to the 5.4 milestone Oct 20, 2021
@IonBazan IonBazan changed the title [Console] add suggestions for debug commands: firewall, form, messenger, router [Console][WIP] add suggestions for debug commands: firewall, form, messenger, router Oct 20, 2021
@IonBazan IonBazan force-pushed the console-suggestions branch 2 times, most recently from 623af59 to 70fdfe3 Compare October 20, 2021 09:57
@IonBazan IonBazan changed the title [Console][WIP] add suggestions for debug commands: firewall, form, messenger, router [Console] add suggestions for debug commands: firewall, form, messenger, router Oct 20, 2021
@carsonbot
Copy link

Hey!

I think @TimoBakx has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@IonBazan IonBazan force-pushed the console-suggestions branch from 70fdfe3 to 5c34db4 Compare October 21, 2021 10:40
@TimoBakx
Copy link
Member

The DebugFirewallCommand part looks good. 👍

Copy link
Member

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, especially on debug:form.

Namespace backslash are missing from completion.

$ bin/console debug:form 
AppFormCommentType                                     SymfonyComponentFormExtensionCoreTypeCheckboxType      SymfonyComponentFormExtensionCoreTypeEmailType         SymfonyComponentFormExtensionCoreTypePasswordType      SymfonyComponentFormExtensionCoreTypeTextType
AppFormPostType                                        SymfonyComponentFormExtensionCoreTypeChoiceType        SymfonyComponentFormExtensionCoreTypeFileType          SymfonyComponentFormExtensionCoreTypePercentType       SymfonyComponentFormExtensionCoreTypeTextareaType
AppFormTypeChangePasswordType                          SymfonyComponentFormExtensionCoreTypeCollectionType    SymfonyComponentFormExtensionCoreTypeFormType          SymfonyComponentFormExtensionCoreTypeRadioType         SymfonyComponentFormExtensionCoreTypeTimeType
AppFormTypeDateTimePickerType                          SymfonyComponentFormExtensionCoreTypeColorType         SymfonyComponentFormExtensionCoreTypeHiddenType        SymfonyComponentFormExtensionCoreTypeRangeType         SymfonyComponentFormExtensionCoreTypeTimezoneType
AppFormTypeTagsInputType                               SymfonyComponentFormExtensionCoreTypeCountryType       SymfonyComponentFormExtensionCoreTypeIntegerType       SymfonyComponentFormExtensionCoreTypeRepeatedType      SymfonyComponentFormExtensionCoreTypeUrlType
AppFormUserType                                        SymfonyComponentFormExtensionCoreTypeCurrencyType      SymfonyComponentFormExtensionCoreTypeLanguageType      SymfonyComponentFormExtensionCoreTypeResetType         SymfonyComponentFormExtensionCoreTypeWeekType
SymfonyBridgeDoctrineFormTypeEntityType                SymfonyComponentFormExtensionCoreTypeDateIntervalType  SymfonyComponentFormExtensionCoreTypeLocaleType        SymfonyComponentFormExtensionCoreTypeSearchType        
SymfonyComponentFormExtensionCoreTypeBirthdayType      SymfonyComponentFormExtensionCoreTypeDateTimeType      SymfonyComponentFormExtensionCoreTypeMoneyType         SymfonyComponentFormExtensionCoreTypeSubmitType        
SymfonyComponentFormExtensionCoreTypeButtonType        SymfonyComponentFormExtensionCoreTypeDateType          SymfonyComponentFormExtensionCoreTypeNumberType        SymfonyComponentFormExtensionCoreTypeTelType           

Option completion is very accurate with a class:

$ bin/console debug:form App\Form\CommentType 
action                        block_name                    csrf_message                  disabled                      getter                        invalid_message               label_html                    priority                      trim                          
allow_extra_fields            block_prefix                  csrf_protection               empty_data                    help                          invalid_message_parameters    label_translation_parameters  property_path                 upload_max_size_message       
allow_file_upload             by_reference                  csrf_token_id                 error_bubbling                help_attr                     is_empty_callback             legacy_error_messages         required                      validation_groups             
attr                          compound                      csrf_token_manager            error_mapping                 help_html                     label                         mapped                        row_attr                      
attr_translation_parameters   constraints                   data                          extra_fields_message          help_translation_parameters   label_attr                    method                        setter                        
auto_initialize               csrf_field_name               data_class                    form_attr                     inherit_data                  label_format                  post_max_size_message         translation_domain            

But fails if backslashes are escaped. I don't know if that should be supported:

$ bin/console debug:form App\\Form\\CommentType 

RuntimeException: The autoloader expected class "App\\Form\\CommentType" to be defined in file "src//Form//CommentType.php". The file was found but the class was not in it, the class name or namespace probably has a typo.

@IonBazan
Copy link
Contributor Author

@GromNaN these missing backslashes seem like an issue with the completion command escaping itself and input escaping. The suggestions provided by the debug:form do contain the backslashes so it must be something wrong with the terminal or the completion engine. Are there any similar issues in other commands too?

@GromNaN
Copy link
Member

GromNaN commented Oct 22, 2021

Same issue with backslashes in #43653.

@wouterj
Copy link
Member

wouterj commented Oct 22, 2021

I've proposed a (quite ugly) fix for the backslashes: #43664 I welcome more testers of this script, as I'm not sure how well this actually works (it works on my machine™)

@IonBazan
Copy link
Contributor Author

@GromNaN please review again

@GromNaN
Copy link
Member

GromNaN commented Oct 27, 2021

LGTM. I used this PR to test #43665 and it worked very well.

Regarding class types, the short names could have been completed in case someone type "ButtonType" for example. But name conflicts can appear and the completion made the FQCN lot easier to type.

@fabpot fabpot force-pushed the console-suggestions branch from cc315d4 to eaf9461 Compare October 30, 2021 08:23
@fabpot
Copy link
Member

fabpot commented Oct 30, 2021

Thank you @IonBazan.

@fabpot fabpot merged commit 9fe0876 into symfony:5.4 Oct 30, 2021
fabpot added a commit that referenced this pull request Oct 30, 2021
This PR was squashed before being merged into the 5.4 branch.

Discussion
----------

[Console] Fix backslash escaping in bash completion

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | #43664
| License       | MIT
| Doc PR        | -

Fully tested code with #43598

- `printf` options `%b` and `%q` are handy to escape string using in shell input.
- Backslashes must to be escaped (doubled) in normal input (`bin/console debug:form App\\Form\\CommentType`). Otherwise they are dropped when PHP receive the argument (`App\Form\CommentType` become `AppFormCommentType` in `$SERVER['argv']`). This is not necessary for quoted arguments (`bin/console debug:form "App\Form\CommentType"` is OK). In the context of a command stored in a variable, like in the bash script, escaping is not interpreted: we must replace `\\` by `\` using `printf '%b'`.
- Completion does not process escaping. If `App\\Form\\` is typed, the suggestions must contain a `\\` to match. Since these values are provided to shell, double backslash must be escaped: `\` becomes `\\\\` in suggestion output.
- I choose to detect when quotes are typed to allow them in completion and add quotes to suggestions.
- Suggestion with spaces are still not properly working.

https://user-images.githubusercontent.com/400034/138536102-e282ee75-56c8-414b-8b16-7c3c290276d7.mov

Commits
-------

e9e0c07 [Console] Fix backslash escaping in bash completion
@IonBazan IonBazan deleted the console-suggestions branch November 1, 2021 01:51
This was referenced Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants