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

Only take the name of the flags and switches when initializing config #218

Merged
merged 2 commits into from
Nov 12, 2015
Merged
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
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