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



44
45
46
47
48
49
50
# File 'lib/turbine/command_runner.rb', line 44

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

#parse_options(*argv) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/turbine/command_runner.rb', line 55

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



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/turbine/command_runner.rb', line 14

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
5
6
7
8
9
10
11
12
# File 'lib/turbine/command_runner.rb', line 3

def setup
  version = read_file("VERSION")
  if version.nil? || version != Turbine::VERSION
    if prompt.agree(Rainbow("The project's momentum configuration is out of date.").red +
      " Would you like to update it?\nWARNING This will overwrite any custom changes made to standard mm commands in this project's `.turbine` folder.", true)
      update_version
      update_standard_commands
    end
  end
end

#teardownObject



52
53
# File 'lib/turbine/command_runner.rb', line 52

def teardown
end