Class: Inspec::Shell
- Inherits:
-
Object
- Object
- Inspec::Shell
- Defined in:
- lib/inspec/shell.rb
Instance Method Summary collapse
- #configure_pry ⇒ Object
-
#initialize(runner) ⇒ Shell
constructor
A new instance of Shell.
- #intro ⇒ Object
- #mark(x) ⇒ Object
- #start ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize(runner) ⇒ Shell
Returns a new instance of Shell.
7 8 9 10 11 12 |
# File 'lib/inspec/shell.rb', line 7 def initialize(runner) @runner = runner # load and configure pry require 'pry' configure_pry end |
Instance Method Details
#configure_pry ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/inspec/shell.rb', line 20 def configure_pry # Remove all hooks and checks Pry.hooks.clear_all that = self # Add the help command Pry::Commands.block_command 'usage', 'Show examples' do that.usage end # Add a help menu as the default intro Pry.hooks.add_hook(:before_session, :intro) do intro end end |
#intro ⇒ Object
40 41 42 43 44 |
# File 'lib/inspec/shell.rb', line 40 def intro puts 'Welcome to the interactive Inspec Shell' puts "To find out how to use it, type: #{mark 'usage'}" puts end |
#mark(x) ⇒ Object
36 37 38 |
# File 'lib/inspec/shell.rb', line 36 def mark(x) "\033[1m#{x}\033[0m" end |
#start ⇒ Object
14 15 16 17 18 |
# File 'lib/inspec/shell.rb', line 14 def start # store context to run commands in this context @runner.add_content('binding.pry', __FILE__, __LINE__) @runner.run end |
#usage ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/inspec/shell.rb', line 46 def usage ctx = @runner.backend puts <<EOF Welcome to the interactive Inspec Shell. You can use resources in this environment to test the target machine. For example: command('uname -a').stdout file('/proc/cpuinfo').content You are currently running on: OS family: #{mark ctx.os[:family] || 'unknown'} OS release: #{mark ctx.os[:release] || 'unknown'} EOF end |