Skip to content

Commit

Permalink
Options available as strings and symbols
Browse files Browse the repository at this point in the history
Closes #106
  • Loading branch information
davetron5000 committed Oct 2, 2012
1 parent 3aeedac commit 132646e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/gli/option_parser_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ def self.setup_accepts(opts,accepts)
def self.setup_options(opts,tokens,options)
tokens.each do |ignore,token|
opts.on(*token.arguments_for_option_parser) do |arg|
[token.name,token.aliases].flatten.compact.each do |name|
[token.name,token.aliases].flatten.compact.map(&:to_s).each do |name|
options[name] = arg
options[name.to_sym] = arg
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions test/tc_gli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,17 +245,27 @@ def test_all_aliases_in_options
c.action do |global,options,args|
assert_equal 'foo',global[:f]
assert_equal global[:f],global[:flag]
assert_equal global[:f],global['f']
assert_equal global[:f],global['flag']
assert_equal global[:f],global['big-flag-name']
assert_equal global[:f],global[:'big-flag-name']

assert global[:s]
assert global[:switch]
assert global[:'big-switch-name']
assert global['s']
assert global['switch']
assert global['big-switch-name']

assert_equal 'bar',options[:g]
assert_equal options[:g],options['g']
assert_equal options[:g],options['gflag']
assert_equal options[:g],options[:gflag]

assert options[:h]
assert options['h']
assert options[:hswitch]
assert options['hswitch']
end
end
@app.run(%w(-f foo -s command -g bar -h some_arg))
Expand Down
14 changes: 10 additions & 4 deletions test/tc_subcommands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def assert_command_ran_with(expected_command,options)
lambda {
@run_results.each do |command,results|
if command == expected_command
assert_equal(Hash(options[:global_options]),results[0])
assert_equal(Hash(options[:command_options]),results[1])
assert_equal(indiffernt_hash(options[:global_options]),results[0])
assert_equal(indiffernt_hash(options[:command_options]),results[1])
assert_equal(options[:args],results[2])
else
assert_nil results
Expand All @@ -133,8 +133,14 @@ def assert_command_ran_with(expected_command,options)
}
end

def Hash(possibly_nil_hash)
possibly_nil_hash || {}
def indiffernt_hash(possibly_nil_hash)
return {} if possibly_nil_hash.nil?
keys = possibly_nil_hash.keys
keys.map(&:to_s).each do |key|
possibly_nil_hash[key.to_sym] = possibly_nil_hash[key] if possibly_nil_hash[key]
possibly_nil_hash[key] = possibly_nil_hash[key.to_sym] if possibly_nil_hash[key.to_sym]
end
possibly_nil_hash
end

# options -
Expand Down

0 comments on commit 132646e

Please sign in to comment.