Method: Inspec::Shell#configure_pry
- Defined in:
- lib/inspec/shell.rb
#configure_pry ⇒ Object
rubocop:disable Metrics/AbcSize
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/inspec/shell.rb', line 27 def configure_pry # rubocop:disable Metrics/AbcSize # Delete any before_session, before_eval, and after_eval hooks so we can # replace them with our own. Pry 0.10 used to have a single method to clear # all hooks, but this was removed in Pry 0.11. [:before_session, :before_eval, :after_eval].each do |event| Pry.hooks.get_hooks(event).keys.map { |hook| Pry.hooks.delete_hook(event, hook) } end that = self # Add the help command Pry::Commands.block_command 'help', 'Show examples' do |resource| that.help(resource) end # configure pry shell prompt 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 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 @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 @runner.load @runner.run_tests if !@runner.all_rules.empty? end # Don't print out control class inspection when the user uses DSL methods. # Instead produce a result of evaluating their control. Pry.config.print = proc do |_output_, value, pry| next if !@runner.all_rules.empty? pry.pager.open do |pager| pager.print pry.config.output_prefix Pry::ColorPrinter.pp(value, pager, Pry::Terminal.width! - 1) end end end |