Method: Inspec::Shell#help

Defined in:
lib/inspec/shell.rb

#help(topic = nil) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
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
# File 'lib/inspec/shell.rb', line 100

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"
    require "inspec/resources"
    resources.sort.each do |resource|
      puts " - #{resource}"
    end
  elsif topic == "matchers"
    print_matchers_help
  elsif !Inspec::Resource.registry[topic].nil? # TODO: fix unnecessary logic
    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\n"
      info += "#{topic_info.example}\n\n"
    end

    info += "#{mark "Web Reference:"}\n\n"
    info += "https://docs.chef.io/inspec/resources/#{topic}\n\n"
    puts info
  else
    begin
      require "inspec/resources/#{topic}"
      help topic
    rescue LoadError
      # TODO: stderr!
      puts "The resource #{topic} does not exist. For a list of valid resources, type: help resources"
    end
  end
end