Module: DJI::Command

Extended by:
ActiveSupport::Autoload
Includes:
Behavior
Defined in:
lib/dji/command.rb,
lib/dji/command/base.rb,
lib/dji/command/behavior.rb,
lib/dji/commands/fedex/fedex_command.rb,
lib/dji/commands/track/track_command.rb,
lib/dji/commands/version/version_command.rb

Defined Under Namespace

Modules: Behavior Classes: Base, FedexCommand, TrackCommand, VersionCommand

Class Method Summary collapse

Class Method Details

.find_by_namespace(name) ⇒ Object

:nodoc:



38
39
40
41
42
43
44
45
# File 'lib/dji/command.rb', line 38

def find_by_namespace(name) # :nodoc:
  lookups = [ name, "dji:#{name}" ]

  lookup(lookups)

  namespaces = subclasses.index_by(&:namespace)
  namespaces[(lookups & namespaces.keys).first]
end

.invoke(namespace, args = [], **config) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dji/command.rb', line 25

def invoke(namespace, args = [], **config)
  namespace = namespace.to_s
  namespace = 'help' if namespace.blank? || Thor::HELP_MAPPINGS.include?(namespace)
  namespace = 'version' if %w( -v --version ).include? namespace

  if command = find_by_namespace(namespace)
    command.perform(namespace, args, config)
  else
    puts "There is no such command: #{namespace}"
    exit
  end
end