Skip to content

Commit

Permalink
Replace all dashes in option names.
Browse files Browse the repository at this point in the history
Without this, you get weird options like:
  opt 'mongodb-cluster-name' -> `mongodb_cluster-name`

After this change:
  opt 'mongodb-cluster-name' => `mongodb_cluster_name`
  • Loading branch information
vStone committed Sep 26, 2021
1 parent 43d2fed commit bb84267
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/cl/opt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions spec/opts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bb84267

Please sign in to comment.