lib/inspec/shell.rb in inspec-4.3.2 vs lib/inspec/shell.rb in inspec-4.6.3

- old
+ new

@@ -1,11 +1,7 @@ -# encoding: utf-8 -# author: Dominik Richter -# author: Christoph Hartmann +require "pry" -require 'pry' - module Inspec # A pry based shell for inspec. Given a runner (with a configured backend and # all that jazz), this shell will produce a pry shell from which you can run # inspec/ruby commands that will be run within the context of the runner. class Shell @@ -17,11 +13,11 @@ # This will hold a single evaluation binding context as opened within # the instance_eval context of the anonymous class that the profile # context creates to evaluate each individual test file. We want to # pretend like we are constantly appending to the same file and want # to capture the local variable context from inside said class. - @ctx_binding = @runner.eval_with_virtual_profile('binding') + @ctx_binding = @runner.eval_with_virtual_profile("binding") configure_pry @ctx_binding.pry end def configure_pry # rubocop:disable Metrics/AbcSize @@ -33,32 +29,32 @@ end that = self # Add the help command - Pry::Commands.block_command 'help', 'Show examples' do |resource| + Pry::Commands.block_command "help", "Show examples" do |resource| that.help(resource) end # configure pry shell prompt - Pry.config.prompt_name = 'inspec' + Pry.config.prompt_name = "inspec" Pry.prompt = [proc { "#{readline_ignore("\e[1m\e[32m")}#{Pry.config.prompt_name}> #{readline_ignore("\e[0m")}" }] # Add a help menu as the default intro - Pry.hooks.add_hook(:before_session, 'inspec_intro') do + Pry.hooks.add_hook(:before_session, "inspec_intro") do intro print_target_info end # Track the rules currently registered and what their merge count is. - Pry.hooks.add_hook(:before_eval, 'inspec_before_eval') do + Pry.hooks.add_hook(:before_eval, "inspec_before_eval") do @runner.reset end # After pry has evaluated a commanding within the binding context of a # test file, register all the rules it discovered. - Pry.hooks.add_hook(:after_eval, 'inspec_after_eval') do + Pry.hooks.add_hook(:after_eval, "inspec_after_eval") do @runner.load @runner.run_tests if !@runner.all_rules.empty? end # Don't print out control class inspection when the user uses DSL methods. @@ -79,11 +75,11 @@ def mark(x) "\e[1m\e[39m#{x}\e[0m" end def intro - puts 'Welcome to the interactive InSpec Shell' + puts "Welcome to the interactive InSpec Shell" puts "To find out how to use it, type: #{mark 'help'}" puts end def print_target_info @@ -112,16 +108,16 @@ command('uname -a').stdout file('/proc/cpuinfo').content => "value" #{print_target_info} EOF - elsif topic == 'resources' + elsif topic == "resources" resources.sort.each do |resource| puts " - #{resource}" end - elsif topic == 'matchers' + elsif topic == "matchers" print_matchers_help - elsif !Inspec::Resource.registry[topic].nil? + elsif !Inspec::Resource.registry[topic].nil? # TODO: fix unnecessary logic topic_info = Inspec::Resource.registry[topic] info = "#{mark 'Name:'} #{topic}\n\n" unless topic_info.desc.nil? info += "#{mark 'Description:'}\n\n" info += "#{topic_info.desc}\n\n"