Sha256: fe3fe959ba26b311739a1c11512db3c79014484c24d9f88d5370f7fe37df0f30

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module Dsu
  module Support
    module Commander
      # Subcommands should extend this module once they are instantiated
      # so that the Subcommand instance has access to all necessary
      # class methods for this subcommand to work.
      module Subcommand
        class << self
          def extended(mod)
            mod.singleton_class.delegate :command_namespace, :commands,
              :command_add, :command_subcommand_add, :command_prompt, :help, to: mod.class
          end
        end

        # Subcommand-specific instance methods.
        #
        # Define Subcommand-specific method equivalents of the Command class
        # methods needed to make this Subcommand instance unique.

        # def command_namespace(namespace = nil)
        #   return @command_namespace || name if namespace.nil?

        #   @command_namespace = namespace
        # end

        # Subcommands can be used by any Command, so the :command_parent needs
        # to be unique to this Subcommand instance.
        def command_parent(parent = nil)
          return @command_prompt if parent.nil?

          @command_prompt = parent
        end

        def command_namespaces(namespaces = [])
          command_parent&.command_namespaces(namespaces)

          namespaces << command_namespace
          namespaces
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
dsu-0.1.0.alpha.5 lib/dsu/support/commander/subcommand.rb
dsu-0.1.0.alpha.4 lib/dsu/support/commander/subcommand.rb
dsu-0.1.0.alpha.3 lib/dsu/support/commander/subcommand.rb
dsu-0.1.0.alpha.2 lib/dsu/support/commander/subcommand.rb
dsu-0.1.0.alpha.1 lib/dsu/support/commander/subcommand.rb