summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTim Rogers <tim@gocardless.com>2015-06-13 18:40:32 +0100
committerTim Rogers <tim@gocardless.com>2015-06-13 18:40:32 +0100
commitfd0e2d8bc3d1c647e6b051f48b8bedbe77934c0c (patch)
tree38105cadafc1b4f0609121b1d2f043af46ed4425 /lib
parent1a075c05d38be0df849119530378043994c05c91 (diff)
downloadslop-fd0e2d8bc3d1c647e6b051f48b8bedbe77934c0c.tar.gz
Better handling of option names with multiple words
Diffstat (limited to 'lib')
-rw-r--r--lib/slop/option.rb2
-rw-r--r--lib/slop/result.rb2
2 files changed, 2 insertions, 2 deletions
diff --git a/lib/slop/option.rb b/lib/slop/option.rb
index 4fd2ae0..2164f1d 100644
--- a/lib/slop/option.rb
+++ b/lib/slop/option.rb
@@ -102,7 +102,7 @@ module Slop
# Returns the last key as a symbol. Used in Options.to_hash.
def key
- (config[:key] || flags.last.sub(/\A--?/, '')).to_sym
+ (config[:key] || flags.last.sub(/\A--?/, '')).tr("-", "_").to_sym
end
# Returns true if this option should be displayed in help text.
diff --git a/lib/slop/result.rb b/lib/slop/result.rb
index eaad707..6f56248 100644
--- a/lib/slop/result.rb
+++ b/lib/slop/result.rb
@@ -33,7 +33,7 @@ module Slop
# Returns an Option if it exists. Ignores any prefixed hyphens.
def option(flag)
- cleaned = -> (f) { f.to_s.sub(/\A--?/, '') }
+ cleaned = -> (f) { f.to_s.sub(/\A--?/, '').tr('_', '-') }
options.find do |o|
o.flags.any? { |f| cleaned.(f) == cleaned.(flag) }
end