Class: Inspec::Resources::Cmd
- Inherits:
-
Object
- Object
- Inspec::Resources::Cmd
- Defined in:
- lib/resources/command.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
Instance Method Summary collapse
- #exist? ⇒ Boolean
- #exit_status ⇒ Object
-
#initialize(cmd) ⇒ Cmd
constructor
A new instance of Cmd.
- #result ⇒ Object
- #stderr ⇒ Object
- #stdout ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(cmd) ⇒ Cmd
Returns a new instance of Cmd.
26 27 28 |
# File 'lib/resources/command.rb', line 26 def initialize(cmd) @command = cmd end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
24 25 26 |
# File 'lib/resources/command.rb', line 24 def command @command end |
Instance Method Details
#exist? ⇒ Boolean
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/resources/command.rb', line 46 def exist? # silent for mock resources return false if inspec.os[:name].to_s == 'unknown' if inspec.os.linux? res = inspec.backend.run_command("bash -c 'type \"#{@command}\"'") elsif inspec.os.windows? res = inspec.backend.run_command("where.exe \"#{@command}\"") elsif inspec.os.unix? res = inspec.backend.run_command("type \"#{@command}\"") else warn "`command(#{@command}).exist?` is not suported on your OS: #{inspec.os[:name]}" return false end res.exit_status.to_i == 0 end |
#exit_status ⇒ Object
42 43 44 |
# File 'lib/resources/command.rb', line 42 def exit_status result.exit_status.to_i end |
#result ⇒ Object
30 31 32 |
# File 'lib/resources/command.rb', line 30 def result @result ||= inspec.backend.run_command(@command) end |
#stderr ⇒ Object
38 39 40 |
# File 'lib/resources/command.rb', line 38 def stderr result.stderr end |
#stdout ⇒ Object
34 35 36 |
# File 'lib/resources/command.rb', line 34 def stdout result.stdout end |
#to_s ⇒ Object
63 64 65 |
# File 'lib/resources/command.rb', line 63 def to_s "Command #{@command}" end |