Skip to content

Commit

Permalink
plugin config aborts and disables when not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
matthutchinson committed Dec 13, 2017
1 parent 8f21424 commit 19d9f3b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion features/lolcommits.feature
Expand Up @@ -120,7 +120,7 @@ Feature: Basic UI functionality
When I run `lolcommits --config --test -p loltext` interactively
And I wait for output to contain "enabled:"
Then I type "false"
Then the output should contain "Successfully configured plugin: loltext"
Then the output should contain "Disabling plugin: loltext - answer with 'true' to enable & configure"
And a file named "~/.lolcommits/test/config.yml" should exist
When I successfully run `lolcommits --test --show-config`
Then the output should match /loltext:\s+enabled: false/
Expand Down
19 changes: 9 additions & 10 deletions lib/lolcommits/configuration.rb
Expand Up @@ -94,16 +94,15 @@ def do_configure!(plugin_name)
config = read_configuration || {}
plugin_name = plugin.class.name
plugin_config = plugin.configure_options!
# having a plugin_config, means configuring went OK
if plugin_config
# save plugin and print config
config[plugin_name] = plugin_config
save(config)
puts self
puts "\nSuccessfully configured plugin: #{plugin_name} at path '#{configuration_file}'"
else
puts "\nAborted plugin configuration for: #{plugin_name}"
end

# save plugin and print config if enabled
config[plugin_name] = plugin_config
save(config)

return unless plugin_config['enabled']

puts self
puts "\nSuccessfully configured plugin: #{plugin_name} at path '#{configuration_file}'"
end

def save(config)
Expand Down
14 changes: 8 additions & 6 deletions lib/lolcommits/plugin/base.rb
Expand Up @@ -45,13 +45,15 @@ def configure_options!
options.reduce({}) do |acc, option|
print "#{option}: "
val = parse_user_input(gets.strip)
# check enabled option isn't a String
if (option == 'enabled') && ![true, false].include?(val)
puts "Aborting - please respond with 'true' or 'false'"
exit 1
else
acc.merge(option => val)
# check enabled option value, disable and abort config if not true
if option == 'enabled'
unless val == true
puts "Disabling plugin: #{self.class.name} - answer with 'true' to enable & configure"
break { option => false }
end
end

acc.merge(option => val)
end
end

Expand Down

0 comments on commit 19d9f3b

Please sign in to comment.