From bb84267d899828c60e882b4920117c5249141f40 Mon Sep 17 00:00:00 2001 From: Jan Vansteenkiste Date: Wed, 25 Sep 2019 14:13:56 +0200 Subject: [PATCH] Replace all dashes in option names. Without this, you get weird options like: opt 'mongodb-cluster-name' -> `mongodb_cluster-name` After this change: opt 'mongodb-cluster-name' => `mongodb_cluster_name` --- lib/cl/opt.rb | 2 +- spec/opts_spec.rb | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) 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