Handle multiple -p port arguments #1627
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue: Currently, if you run
start-storybook
and specify the port with-p
multiple times, it errors out withError: port to run Storybook is required!
This is due to a quirk of how commander passes multiple args to the option formatter parameter, leading toparseInt
getting called with a weird 2nd parameter and ultimatelyprogram.port
being set to NaN. See, for example, tj/commander.js#523This bug probably came up because the example on commander's README erroneously uses parseInt in this same way.
This is annoying when I have multiple checkouts of a project using storybook with the automatically added npm script:
"storybook": "start-storybook -p 6006"
. If I want to run multiple storybook instances, I would expect to be able to donpm run storybook
in one checkout, and thennpm run storybook -- -p 6007
in the other to override the port number (It would expand tostart-storybook -p 6006 -p 6007
)Most CLI programs interpret extra instances of an argument to override previous instances. For example:
ls -l --block-size=1 --block-size=16
uses 16 as the block size.What I did
Changed the commander option parsing function to pass only the first parameter to
parseInt
and call it with a specified radix.How to test
Get this branch's
start-storybook
linked into some project with storybook setup, thenstart-storybook -p 6006 -p 6007
should start storybook running on port 6007.