Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace all dashes in option names. #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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