diff --git a/lib/cl/opt.rb b/lib/cl/opt.rb index b79ddd6..46a03f5 100644 --- a/lib/cl/opt.rb +++ b/lib/cl/opt.rb @@ -37,7 +37,7 @@ def define(const) def name return @name if instance_variable_defined?(:@name) name = long.split(' ').first.match(OPT)[1] if long - @name = name.sub('-', '_').to_sym if name + @name = name.gsub('-', '_').to_sym if name end def type diff --git a/spec/opts_spec.rb b/spec/opts_spec.rb index 3bba6d4..aba909f 100644 --- a/spec/opts_spec.rb +++ b/spec/opts_spec.rb @@ -52,13 +52,16 @@ end describe 'dashed opts' do - let(:opts) { ->(*) { opt('--one_two') } } + let(:opts) { ->(*) { opt('--one_two_three') } } - it { expect(cmd(%w(cmd --one_two)).opts[:one_two]).to be true } - it { expect(cmd(%w(cmd --one_two)).one_two?).to be true } + it { expect(cmd(%w(cmd --one_two_three)).opts[:one_two_three]).to be true } + it { expect(cmd(%w(cmd --one_two_three)).one_two_three?).to be true } - it { expect(cmd(%w(cmd --one-two)).opts[:one_two]).to be true } - it { expect(cmd(%w(cmd --one-two)).one_two?).to be true } + it { expect(cmd(%w(cmd --one-two-three)).opts[:one_two_three]).to be true } + it { expect(cmd(%w(cmd --one-two-three)).one_two_three?).to be true } + + it { expect(cmd(%w(cmd --one-two_three)).opts[:one_two_three]).to be true } + it { expect(cmd(%w(cmd --one_two-three)).one_two_three?).to be true } end describe 'does not dasherize values' do