mirror of
https://github.com/inspec/inspec
synced 2024-09-20 14:31:58 +00:00
feature: add interactive shell
This commit is contained in:
parent
6799af8ce5
commit
6aee38a23c
3 changed files with 60 additions and 0 deletions
|
@ -16,4 +16,5 @@ require 'vulcano/resource'
|
|||
require 'vulcano/rspec_json_formatter'
|
||||
require 'vulcano/rule'
|
||||
require 'vulcano/runner'
|
||||
require 'vulcano/shell'
|
||||
require 'matchers/matchers'
|
||||
|
|
58
lib/vulcano/shell.rb
Normal file
58
lib/vulcano/shell.rb
Normal file
|
@ -0,0 +1,58 @@
|
|||
# encoding: utf-8
|
||||
# author: Dominik Richter
|
||||
# author: Christoph Hartmann
|
||||
|
||||
module Vulcano::Shell
|
||||
def self.start(runner)
|
||||
# load and configure pry
|
||||
require 'pry'
|
||||
configure_pry
|
||||
|
||||
runner.add_content('binding.pry', __FILE__, __LINE__)
|
||||
runner.run
|
||||
end
|
||||
|
||||
def self.configure_pry
|
||||
# Remove all hooks and checks
|
||||
Pry.hooks.clear_all
|
||||
|
||||
# Add the help command
|
||||
Pry::Commands.block_command 'usage', 'Show examples' do
|
||||
Vulcano::Shell.usage
|
||||
end
|
||||
|
||||
# Add a help menu as the default intro
|
||||
Pry.hooks.add_hook(:before_session, :intro) do
|
||||
intro
|
||||
end
|
||||
end
|
||||
|
||||
def self.mark(x)
|
||||
"\033[1m#{x}\033[0m"
|
||||
end
|
||||
|
||||
def self.intro
|
||||
puts 'Welcome to the interactive Vulcano Shell'
|
||||
puts "To find out how to use it, type: #{mark 'usage'}"
|
||||
puts
|
||||
end
|
||||
|
||||
def self.usage
|
||||
puts <<EOF
|
||||
|
||||
Welcome to the interactive Vulcano 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 os[:family] || 'unknown'}
|
||||
OS release: #{mark os[:release] || 'unknown'}
|
||||
|
||||
EOF
|
||||
end
|
||||
end
|
|
@ -29,4 +29,5 @@ Gem::Specification.new do |spec|
|
|||
spec.add_dependency 'mixlib-shellout', '~> 2'
|
||||
spec.add_dependency 'specinfra', '~> 2.40'
|
||||
spec.add_dependency 'docker-api', '~> 1.22'
|
||||
spec.add_dependency 'pry', '~> 0.10'
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue