lib/chef/fork/commands/help.rb in chef-fork-0.1.1 vs lib/chef/fork/commands/help.rb in chef-fork-0.1.2
- old
+ new
@@ -1,17 +1,34 @@
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
-require "rbconfig"
require "chef/fork/commands"
+require "json"
+require "rbconfig"
class Chef
class Fork
module Commands
class Help < Noop
def run(args=[])
- ruby = File.join(RbConfig::CONFIG["bindir"], RbConfig::CONFIG["ruby_install_name"])
- exit(system(ruby, $0, "--help") ? 0 : 1)
+ if command = args.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
end
end
end
end