Skip to content

Commit

Permalink
Merge pull request #1475 from chef/adamleff/show-target-in-shell
Browse files Browse the repository at this point in the history
Provide target info on shell invocation
  • Loading branch information
arlimus authored Feb 14, 2017
2 parents 09cc7c3 + bc7db89 commit 34247f7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/inspec/shell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def configure_pry # rubocop:disable Metrics/AbcSize
# Add a help menu as the default intro
Pry.hooks.add_hook(:before_session, 'inspec_intro') do
intro
print_target_info
puts
end

# Track the rules currently registered and what their merge count is.
Expand Down Expand Up @@ -94,10 +96,20 @@ def intro
puts
end

def print_target_info
ctx = @runner.backend
puts <<EOF
You are currently running on:
OS platform: #{mark ctx.os[:name] || 'unknown'}
OS family: #{mark ctx.os[:family] || 'unknown'}
OS release: #{mark ctx.os[:release] || 'unknown'}
EOF
end

def help(resource = nil)
if resource.nil?

ctx = @runner.backend
puts <<EOF
Available commands:
Expand All @@ -110,14 +122,9 @@ def help(resource = nil)
You can use resources in this environment to test the target machine. For example:
command('uname -a').stdout
file('/proc/cpuinfo').content => "value",
You are currently running on:
OS platform: #{mark ctx.os[:name] || 'unknown'}
OS family: #{mark ctx.os[:family] || 'unknown'}
OS release: #{mark ctx.os[:release] || 'unknown'}
file('/proc/cpuinfo').content => "value"
#{print_target_info}
EOF
elsif resource == 'resources'
resources
Expand Down
5 changes: 5 additions & 0 deletions test/functional/inspec_shell_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ def do_shell(code, exit_status = 0, stderr = '')
out
end

it 'displays the target device information for the user without requiring the help command' do
out = do_shell('1+1')
out.stdout.must_include 'You are currently running on:'
end

it 'provides a help command' do
out = do_shell('help')
out.stdout.must_include 'Available commands:'
Expand Down

0 comments on commit 34247f7

Please sign in to comment.