dthree / vorpal

Node's framework for interactive CLIs
http://vorpal.js.org
MIT License
5.64k stars 280 forks source link

Default help command does not support commands that are not entirely lower case #309

Open ghost opened 6 years ago

ghost commented 6 years ago

I am using your library in a custom project which does not adhere to usual UNIX standards when naming the commands. It uses commands akin to PowerShell commandlets as in Write-Output. I wanted to rename help to Get-Help with a custom hook (either using mock or manually overriding Module.prototype.load) which had some since Get-Help Write-Output would not print the expected help for the particular Write-Output command.

After reverting my rename it turns out with your default help Write-Output the output is still Invalid command. After looking through the code for far too long it turns out that this line the culprit:

https://github.com/dthree/vorpal/blob/2073ad9d77b02a05b86f122ef473a10f164e43ba/lib/vorpal-commons.js#L27

Your default help command is calling toLowerCase on the argument and then looking for a write-output command. However debugging yields that the name of the command is not altered when creating it and still being Write-Output.

In order to fix this it is only necessary to remove the linked call toLowerCase. Unfortunately there are still two occurences of it:

https://github.com/dthree/vorpal/blob/2073ad9d77b02a05b86f122ef473a10f164e43ba/lib/vorpal.js#L892

https://github.com/dthree/vorpal/blob/2073ad9d77b02a05b86f122ef473a10f164e43ba/lib/vorpal.js#L1091

I haven't figured out what they are exactly doing and whether my first change will break something. Once I know more and was able to test the change I am considering to open a pull request to fix this.