rails / thor

Thor is a toolkit for building powerful command-line interfaces.
http://whatisthor.com/
MIT License
5.12k stars 553 forks source link

🌈 Need to dup default or else we have a troublesome alias #715

Closed tsontario closed 4 years ago

tsontario commented 4 years ago

Following work on https://github.com/Shopify/krane/issues/697, I discovered a subtle bug that is now causing issues with the repeatable flag feature.

If a default argument for a Thor::Option | Thor::Argument is provided, the option/argument constructor will call:

@assigns[argument.human_name] = argument.default

This aliases, and does not create a copy of, argument.default to @assigns[argument.human_name]. So now every time we update @assigns, we are also mutating argument.default. This was never a problem before because, without a repeatable flag, we'd never encounter a failure mode.

TODO