Class: Rocketwheel::Command::CLI::Base

Inherits:
Thor
  • Object
show all
Defined in:
lib/rocketwheel/command/cli.rb

Direct Known Subclasses

Build, Deploy, Encode

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object

Intercept missing methods and search subtasks for them



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rocketwheel/command/cli.rb', line 50

def method_missing(meth, *args)
  meth = meth.to_s

  if self.class.map.has_key?(meth)
    meth = self.class.map[meth]
  end

  klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")

  if klass.nil?
    tasks_dir = File.join(Dir.pwd, "tasks")

    if File.exists?(tasks_dir)
      Dir[File.join(tasks_dir, "**/*_task.rb")].each { |f| require f }
      klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
    end
  end

  if klass.nil?
    raise Thor::Error.new "There's no '#{meth}' command. Try 'rocket help' for a list of commands."
  else
    args.unshift(task) if task
    klass.start(args, :shell => self.shell)
  end
end

Class Method Details

.filenameObject



16
17
18
# File 'lib/rocketwheel/command/cli.rb', line 16

def filename
  Rocketwheel::Command::MANIFEST
end

.start(*args) ⇒ Object



9
10
11
12
13
14
# File 'lib/rocketwheel/command/cli.rb', line 9

def start(*args)
  # Change flag to a module
  ARGV.unshift('help') if ARGV.delete('--help')

  super
end

Instance Method Details

#help(meth = nil, subcommand = false) ⇒ void

This method returns an undefined value.

Override the Thor help method to find help for subtasks



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/rocketwheel/command/cli.rb', line 31

def help(meth = nil, subcommand = false)
  if meth && !self.respond_to?(meth)
    klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
    klass.start(["-h", task].compact, :shell => self.shell)
  else
    list = []
    Thor::Util.thor_classes_in(Rocketwheel::Command::CLI).each do |klass|
      list += klass.printable_tasks(false)
    end
    list.sort!{ |a,b| a[0] <=> b[0] }

    shell.say "Tasks:"
    shell.print_table(list, :ident => 2, :truncate => true)
    shell.say
  end
end

#versionObject



22
23
24
25
# File 'lib/rocketwheel/command/cli.rb', line 22

def version
  require 'rocketwheel/command/version'
  say "Rocketwheel Command #{Rocketwheel::Command::VERSION}"
end