Sha256: ec205f2ba39b944bfa5e11301486a3ccc19201ed0669d10f2b35c519df79861b

Contents?: true

Size: 1.05 KB

Versions: 8

Compression:

Stored size: 1.05 KB

Contents

require 'forwardable'

require 'byebug/helpers/reflection'
require 'byebug/command_list'

module Byebug
  #
  # Subcommand additions.
  #
  module Subcommands
    def self.included(command)
      command.extend(ClassMethods)
    end

    extend Forwardable
    def_delegators :'self.class', :subcommand_list

    #
    # Delegates to subcommands or prints help if no subcommand specified.
    #
    def execute
      subcmd_name = @match[1]
      return puts(help) unless subcmd_name

      subcmd = subcommand_list.match(subcmd_name)
      fail CommandNotFound.new(subcmd_name, self.class) unless subcmd

      subcmd.new(processor, arguments).execute
    end

    #
    # Class methods added to subcommands
    #
    module ClassMethods
      include Helpers::ReflectionHelper

      #
      # Default help text for a command with subcommands
      #
      def help
        super + subcommand_list.to_s
      end

      #
      # Command's subcommands.
      #
      def subcommand_list
        @subcommand_list ||= CommandList.new(commands)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
byebug-8.2.2 lib/byebug/subcommands.rb
byebug-8.2.1 lib/byebug/subcommands.rb
byebug-8.2.0 lib/byebug/subcommands.rb
byebug-8.1.0 lib/byebug/subcommands.rb
byebug-8.0.1 lib/byebug/subcommands.rb
byebug-8.0.0 lib/byebug/subcommands.rb
byebug-7.0.0 lib/byebug/subcommands.rb
byebug-6.0.2 lib/byebug/subcommands.rb