Module: Clin::CommandMixin::Dispatcher::ClassMethods

Defined in:
lib/clin/command_mixin/dispatcher.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_redispatch_argsObject

Returns the value of attribute _redispatch_args.



7
8
9
# File 'lib/clin/command_mixin/dispatcher.rb', line 7

def _redispatch_args
  @_redispatch_args
end

Instance Method Details

#dispatch(args, prefix: nil, commands: nil) ⇒ Object

Redispatch the command to a sub command with the given arguments If no commands are given it will look for Clin::Command in the class namespace e.g. If those 2 classes are defined. ‘MyDispatcher < Clin::Command` and `MyDispatcher::ChildCommand < Clin::Command` Will test against ChildCommand

Parameters:

  • args (Array<String>|String)

    New argument to parse

  • prefix (String) (defaults to: nil)

    Prefix to add to the beginning of the command

  • commands (Array<Clin::Command.class>) (defaults to: nil)

    Commands that will be tried against



17
18
19
# File 'lib/clin/command_mixin/dispatcher.rb', line 17

def dispatch(args, prefix: nil, commands: nil)
  @_redispatch_args = [[*args], prefix, commands]
end

#dispatch_doc(opts) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/clin/command_mixin/dispatcher.rb', line 25

def dispatch_doc(opts)
  return if _redispatch_args.nil?
  opts.separator 'Examples: '
  commands = (_redispatch_args[2] || default_commands)
  commands.each do |cmd_cls|
    opts.separator "\t#{cmd_cls.usage}"
  end
end

#redispatch?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/clin/command_mixin/dispatcher.rb', line 21

def redispatch?
  !@_redispatch_args.nil?
end