Method: Inspec::Shell#help

Defined in:
lib/inspec/shell.rb

#help(topic = nil) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/inspec/shell.rb', line 114

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

    puts <<~EOF
      Available commands:

          `[resource]` - run resource on target machine
          `help resources` - show all available resources that can be used as commands
          `help [resource]` - information about a specific resource
          `help matchers` - show information about common matchers
          `exit` - exit the InSpec shell

      You can use resources in this environment to test the target machine. For example:

          command('uname -a').stdout
          file('/proc/cpuinfo').content => "value"

      #{print_target_info}
    EOF
  elsif topic == 'resources'
    resources.sort.each do |resource|
      puts " - #{resource}"
    end
  elsif topic == 'matchers'
    print_matchers_help
  elsif !Inspec::Resource.registry[topic].nil?
    topic_info = Inspec::Resource.registry[topic]
    info = "#{mark 'Name:'} #{topic}\n\n"
    unless topic_info.desc.nil?
      info += "#{mark 'Description:'}\n\n"
      info += "#{topic_info.desc}\n\n"
    end

    unless topic_info.example.nil?
      info += "#{mark 'Example:'}\n"
      info += "#{print_example(topic_info.example)}\n\n"
    end

    info += "#{mark 'Web Reference:'}\n\n"
    info += "https://www.inspec.io/docs/reference/resources/#{topic}\n\n"
    puts info
  else
    puts "The resource #{topic} does not exist. For a list of valid resources, type: help resources"
  end
end