Filter out commands before parsing requirements#625
Conversation
|
Hmm... I see the change is minimal and the tests are passing as is (which means that if we merge this, we need to have a test that validates it). However, I am not sure about this new order. The command line structure is how the user communicates with the program. If an incomplete command is given, the first logical block in my mind is tell the user their communication is misunderstood. For example, with this change, you can run Another thing that guides the order of execution here, is that code that belongs in developer-space, usually comes after code that belongs in bashly-space. Filters are developer-space - by that I mean, imagine if the filters functionality was not present in bashly, then the developer would place it as the first thing inside the function - which would mean that the user must use a valid command before they can reach this piece of code. And finally, I am concerned about unwanted side effects. For example, one thing that I spot is that if this change is staying, it needs to go even higher in the code, since the below bashly.yml does not behave as expected: name: cli
help: Sample application
version: 0.1.0
commands:
- name: redis
help: Perform actions in redis
filters: [redis_running]
commands:
- name: backup
args:
- name: id
required: true
help: ID of something
- name: restore
args:
- name: id
required: true
help: ID of somethingOutput the "old" order - first syntax then filter: I need to think about it and perhaps hear more opinions for or against. |
|
@meleu - I found another advantage for the pre-PR filter order: You have In fact, since the filter is last, everything is available to you, as one might expect. Real life scenarios for it:
|
|
Yeah, your points convinced me. It's better to keep the logic as is. Closing this. |
Context: filters
Currently it's required to give a complete valid command line in order to be informed the subcommand is not available.
This MR makes the filter logic happen before parsing the requirements.
Example of the current unwanted behavior 👇
I want to be informed the command is invalid earlier, even with an incomplete command.
After the change in this MR the behavior is to informe the user the subcommand is not available even if the whole command line is "incomplete":