Sha256: 2eec7b6cdb4a0642861ce9ea7e2f99cb5795d8384c72254e24b543adad439fef

Contents?: true

Size: 992 Bytes

Versions: 3

Compression:

Stored size: 992 Bytes

Contents

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

require "chef/fork/commands"
require "json"
require "rbconfig"

class Chef
  class Fork
    module Commands
      class Help < Noop
        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
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chef-fork-0.2.0 lib/chef/fork/commands/help.rb
chef-fork-0.1.4 lib/chef/fork/commands/help.rb
chef-fork-0.1.3 lib/chef/fork/commands/help.rb