Sha256: 905c385a219d2639eec5e034214f51cc42cff701bd83976ada0e635d9e3bcf61

Contents?: true

Size: 958 Bytes

Versions: 1

Compression:

Stored size: 958 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=[])
          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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
chef-fork-0.1.2 lib/chef/fork/commands/help.rb