Sha256: 0eedf3e078717262afdcba219c84fc702dc52c5dbad4fa464a8e52786859aa8d

Contents?: true

Size: 710 Bytes

Versions: 6

Compression:

Stored size: 710 Bytes

Contents

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

    arg :args, splat: true

    def run
      ctx.puts help
    end

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

    def help?
      true
    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

6 entries across 6 versions & 2 rubygems

Version Path
travis-cl-1.2.4 lib/cl/help.rb
cl-1.2.4 lib/cl/help.rb
cl-1.2.3 lib/cl/help.rb
cl-1.2.2 lib/cl/help.rb
cl-1.2.1 lib/cl/help.rb
cl-1.2.0 lib/cl/help.rb