Sha256: 5f91b5eba33b69c8722ef71ab6c6673a55703a716f7f35c76f3b3abe191b22b6

Contents?: true

Size: 641 Bytes

Versions: 17

Compression:

Stored size: 641 Bytes

Contents

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

    def run
      ctx.puts help
    end

    def help
      args.any? ? Cmd.new(ctx, cmd).format : Cmds.new(ctx, 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

17 entries across 17 versions & 1 rubygems

Version Path
cl-1.1.5 lib/cl/help.rb
cl-1.1.4 lib/cl/help.rb
cl-1.1.3 lib/cl/help.rb
cl-1.1.2 lib/cl/help.rb
cl-1.1.1 lib/cl/help.rb
cl-1.1.0 lib/cl/help.rb
cl-1.0.5 lib/cl/help.rb
cl-1.0.4 lib/cl/help.rb
cl-1.0.3 lib/cl/help.rb
cl-1.0.2 lib/cl/help.rb
cl-1.0.1 lib/cl/help.rb
cl-1.0.0 lib/cl/help.rb
cl-0.1.28 lib/cl/help.rb
cl-0.1.27 lib/cl/help.rb
cl-0.1.26 lib/cl/help.rb
cl-0.1.25 lib/cl/help.rb
cl-0.1.24 lib/cl/help.rb