Class: Chef::Fork::Commands::Help

Inherits:
Noop
  • Object
show all
Defined in:
lib/chef/fork/commands/help.rb

Instance Method Summary collapse

Methods inherited from Noop

#initialize

Constructor Details

This class inherits a constructor from Chef::Fork::Commands::Noop

Instance Method Details

#run(args = []) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/chef/fork/commands/help.rb', line 12

def run(args=[])
  rest = order_args(args)
  if command = rest.shift
    case command
    when "commands"
      paths = $LOAD_PATH.map { |path|
        File.join(path, "chef", "fork", "commands")
      }
      commands = paths.map { |path|
        Dir.glob(File.join(path, "*.rb")).map { |file| File.basename(file, ".rb") }
      }.flatten
      STDOUT.puts(JSON.pretty_generate(commands.sort.uniq))
    else
      raise(NotImplementedError.new(command.inspect))
    end
  else
    ruby = File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"])
    exec(ruby, $0, "--help")
    exit(127)
  end
end