Sha256: be3c82eb0ca0abe6982bd3a2387fac8ff1b6d3df1c9a35608a4239074a5a1b39

Contents?: true

Size: 631 Bytes

Versions: 24

Compression:

Stored size: 631 Bytes

Contents

class Cl
  class Help < Cl::Cmd
    register :help

    def run
      ctx.puts help
    end

    def help
      args.any? ? Cmd.new(cmd).format : Cmds.new(cmds).format
    end

    private

      def cmds
        cmds = Cl::Cmd.cmds.reject { |cmd| cmd.registry_key == :help }
        key  = args.join(':') if args
        cmds = cmds.select { |cmd| cmd.registry_key.to_s.start_with?(key) } if key
        cmds
      end

      def cmd
        key = args.join(':')
        return Cl::Cmd[key] if Cl::Cmd.registered?(key)
        ctx.abort("Unknown command: #{key}")
      end
  end
end

require 'cl/help/cmd'
require 'cl/help/cmds'

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
cl-0.1.3 lib/cl/help.rb
cl-0.1.2 lib/cl/help.rb
cl-0.1.1 lib/cl/help.rb
cl-0.1.0 lib/cl/help.rb