Module: Katana

Defined in:
lib/katana.rb

Constant Summary collapse

CONFIG_PATH =
"config/katana.yml"

Class Method Summary collapse

Class Method Details

.runObject



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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/katana.rb', line 10

def run
  @env = ARGV.shift
  if @env == "init"
    init(ARGV.shift)
    exit
  end

  unless File.exists?(CONFIG_PATH)
    puts "Cannot find #{CONFIG_PATH}.  Run \"kat init your-app-name\" to create it."
    exit
  end

  @config = YAML.load_file(CONFIG_PATH)[@env]
  if !@config
    puts "Cannot find \"#{@env}\" environment in #{CONFIG_PATH}."
    exit
  end

  command = ARGV.shift || ""
  path = ARGV.join(" ")

  case command
  when "create"
    lc("heroku create #{@config["app"]}")

  when "deploy"
    lc("git push #{@env} master")
    hc("rake", "db:migrate")
    hc("restart")

  when "deploy:setup"
    lc("git init") unless File.exists?(".git")

    remotes = `git remote`.split("\n").select{|v| v == @env or v == "heroku"}
    git_commands = remotes.map{|v| "git remote rm #{v}"}
    git_commands << "git remote add #{@env} [email protected]:#{@config["app"]}.git"
    lc(git_commands.join(" && "))

    update_config
    update_stack

  when "config:update"
    update_config

  when "stack:update"
    update_stack

  when ""
    puts "Please specify a command."

  else
    # pass the command to heroku
    hc(command, path)
  end
end