Skip to content

Commit

Permalink
Merge pull request #218 from ZeroPointEnergy/fix/config_initialization
Browse files Browse the repository at this point in the history
Only take the name of the flags and switches when initializing config
  • Loading branch information
davetron5000 committed Nov 12, 2015
2 parents e61264d + 460c687 commit 40db067
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/gli/commands/initconfig.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def initialize(config_file_name,commands,flags,switches)
private

def create_config(global_options,options,arguments)
config = Hash[global_options.map { |option_name,option_value|
config = Hash[(@app_switches.keys + @app_flags.keys).map { |option_name|
option_value = global_options[option_name]
if option_value.kind_of?(String) && option_value.respond_to?(:force_encoding)
[option_name,option_value.force_encoding("utf-8")]
else
Expand Down
10 changes: 6 additions & 4 deletions test/tc_gli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ def test_initconfig_command
@app.reset
@app.config_file(@config_file)
@app.flag :f
@app.switch :s
@app.switch :s, :salias
@app.switch :w
@app.flag :bigflag
@app.flag :bigflag, :bigalias
@app.flag :biggestflag
@app.command :foo do |c|
end
Expand All @@ -249,7 +249,9 @@ def test_initconfig_command

assert_equal 'foo',written_config[:f]
assert_equal 'bleorgh',written_config[:bigflag]
assert !written_config[:bigalias]
assert written_config[:s]
assert !written_config[:salias]
assert !written_config[:w]
assert_nil written_config[:biggestflag]
assert written_config[GLI::InitConfig::COMMANDS_KEY]
Expand Down Expand Up @@ -515,7 +517,7 @@ def test_switch_with_default_true_and_not_negatable_causes_exception
end
@switch_value = nil

assert_raises(RuntimeError) do
assert_raises(RuntimeError) do
@app.command [:foo] do |c|
c.switch :switch, :default_value => true, :negatable => false
end
Expand Down Expand Up @@ -770,7 +772,7 @@ def some_descriptions
}
end

def assert_switch_was_made(object,switch)
def assert_switch_was_made(object,switch)
lambda {
assert object.switches[switch]
assert_equal @description,object.switches[switch].description,"For switch #{switch}"
Expand Down

0 comments on commit 40db067

Please sign in to comment.