lib/plugins/puppet-debugger/input_responders/set.rb in puppet-debugger-0.19.0 vs lib/plugins/puppet-debugger/input_responders/set.rb in puppet-debugger-1.0.0

- old
+ new

@@ -1,30 +1,32 @@ +# frozen_string_literal: true + require 'puppet-debugger/input_responder_plugin' module PuppetDebugger module InputResponders class Set < InputResponderPlugin - COMMAND_WORDS = %w(set :set) + COMMAND_WORDS = %w[set :set].freeze SUMMARY = 'Set the a puppet debugger config' COMMAND_GROUP = :scope - KEYWORDS = %w(node loglevel) - LOGLEVELS = %w(debug info) + KEYWORDS = %w[node loglevel].freeze + LOGLEVELS = %w[debug info].freeze def self.command_completion(buffer_words) next_word = buffer_words.shift case next_word - when 'loglevel' - if buffer_words.count > 0 - LOGLEVELS.grep(/^#{Regexp.escape(buffer_words.first)}/) - else - LOGLEVELS - end - when 'debug', 'info','node' - [] - when nil - %w(node loglevel) + when 'loglevel' + if buffer_words.count.positive? + LOGLEVELS.grep(/^#{Regexp.escape(buffer_words.first)}/) else - KEYWORDS.grep(/^#{Regexp.escape(next_word)}/) + LOGLEVELS + end + when 'debug', 'info', 'node' + [] + when nil + %w[node loglevel] + else + KEYWORDS.grep(/^#{Regexp.escape(next_word)}/) end end def run(args = []) handle_set(args) @@ -35,27 +37,27 @@ def handle_set(input) output = '' # args = input.split(' ') # args.shift # throw away the set case input.shift - when /node/ - if name = input.shift - output = "Resetting to use node #{name}" - debugger.set_scope(nil) - debugger.set_node(nil) - debugger.set_facts(nil) - debugger.set_environment(nil) - debugger.set_compiler(nil) - set_log_level(debugger.log_level) - debugger.set_remote_node_name(name) - else - debugger.out_buffer.puts 'Must supply a valid node name' - end - when /loglevel/ - if level = input.shift - set_log_level(level) - output = "loglevel #{Puppet::Util::Log.level} is set" - end + when /node/ + if name = input.shift + output = "Resetting to use node #{name}" + debugger.set_scope(nil) + debugger.set_node(nil) + debugger.set_facts(nil) + debugger.set_environment(nil) + debugger.set_compiler(nil) + set_log_level(debugger.log_level) + debugger.set_remote_node_name(name) + else + debugger.out_buffer.puts 'Must supply a valid node name' + end + when /loglevel/ + if level = input.shift + set_log_level(level) + output = "loglevel #{Puppet::Util::Log.level} is set" + end end output end def set_log_level(level)