Module: Turbine::CommandRunner

Included in:
Application
Defined in:
lib/turbine/command_runner.rb

Instance Method Summary collapse

Instance Method Details

#init_and_exit(*argv) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/turbine/command_runner.rb', line 36

def init_and_exit(*argv)
  setup
  parse_options(*argv)
  init
  teardown
  exit
end

#parse_options(*argv) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/turbine/command_runner.rb', line 47

def parse_options(*argv)
  option_parser.on("-t", "=HOURS", Float) do |hours|
    params[:hours] = hours
  end

  option_parser.on("-m", "=MSG", String) do |msg|
    params[:message] = msg
  end

  option_parser.on("-k", "=KEY", String) do |msg|
    params[:api_key] = msg
  end

  command, *arguments = option_parser.parse(*argv)

  self.command = command
  params[:arguments] = arguments
end

#run(argv) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/turbine/command_runner.rb', line 6

def run(argv)
  init_and_exit(*argv) if argv[0] == "init"

  unless self.class.config_dir
    prompt.say "Cannot find config file.  Did you forget to run mm init?"
    return
  end

  require "#{self.class.config_dir}/config"

  if self.class.global_config_dir
    Dir["#{self.class.global_config_dir}/commands/*.rb"].each { |f| load f }
  end

  self.class.extensions.each do |extension|
    extend(extension)
  end

  setup
  parse_options(*argv)

  if command && respond_to?(command)
    send(command)
  else 
    prompt.say("Unknown command: #{command}")
  end

  teardown
end

#setupObject



3
4
# File 'lib/turbine/command_runner.rb', line 3

def setup
end

#teardownObject



44
45
# File 'lib/turbine/command_runner.rb', line 44

def teardown
end