Class: Bonethug::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/bonethug/cli.rb

Class Method Summary collapse

Class Method Details

.display_helpObject



153
154
155
# File 'lib/bonethug/cli.rb', line 153

def self.display_help
  puts 'Usage: bonethug task [argument]...'
end

.handleObject



4
5
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
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/bonethug/cli.rb', line 4

def self.handle

  # what are we doing?
  task = ARGV[0] || 'help'

  case task

  when 'help'

    display_help

  when 'install'

    # handle args
    type = ARGV[1]
    location = ARGV[2] || '.'

    # validate
    unless type
      puts 'Usage: bonethug install [type] [location]'
      return
    end
    
    # run the installer
    Installer.install type, location

  when 'init', 'update'

    # handle args
    location = ARGV[1] || '.'

    # validate
    unless location
      puts 'Usage: bonethug #{task} [location]'
      return
    end

    # run the initaliser
    Installer.bonethugise(location, task.to_sym)

  when  'run', 
        'rake', 
        'drush', 
        'sake'

    # get env
    environment = ARGV.last

    # handle args
    if task == 'run'
      cmd_task = ARGV[1]
      args = ARGV[2..(ARGV.length-2)]
    else
      case task
      when 'rake'
        cmd_task = 'rake'
      when 'drush'
        cmd_task = 'vendor/drush/drush'
      when 'sake'
        cmd_task = 'public/framework/sake'
      end
      args = ARGV[1..(ARGV.length-2)]
    end

    # build command
    run = "\"run[#{cmd_task} #{args.join(' ')}]\""

    # do it!
    exec "export to=#{environment} && bundle exec mina -f .bonethug/deploy.rb #{run} --verbose"         

  when  'deploy', 
        'setup', 
        'remote-backup', 
        'local-backup', 
        'sync-backup-to', 
        'sync-backup-from', 
        'sync-local-to', 
        'sync-local-from', 
        'init-db', 
        'force-unlock', 
        'cleanup'

    # handle args
    environment = ARGV[1]

    # validate
    unless environment
      puts 'Usage: bonethug #{task} [environment]' 
      return
    end

    case task

    # Setup and Deploy
    when 'deploy'
      exec "export to=#{environment} && bundle exec mina -f .bonethug/deploy.rb deploy --verbose"
    when 'setup'
      exec "export to=#{environment} && bundle exec mina -f .bonethug/deploy.rb setup --verbose"

    # remote mina scripts
    when 'init-db'
      exec "export to=#{environment} && bundle exec mina -f .bonethug/deploy.rb init_db --verbose"
    when 'force-unlock'
      exec "export to=#{environment} && bundle exec mina -f .bonethug/deploy.rb deploy:force_unlock --verbose"
    when 'cleanup'
      exec "export to=#{environment} && bundle exec mina -f .bonethug/deploy.rb deploy:cleanup --verbose"      

    # Snapshot Backup
    when 'remote-backup'
      exec "export to=#{environment} && bundle exec mina -f .bonethug/deploy.rb backup --verbose"                   
    when 'local-backup'
      exec "export to=#{environment} && bundle exec astrails-safe .bonethug/backup.rb"

    # Synchronised backup
    when 'sync-backup-to'
      exec "export to=#{environment} && bundle exec mina -f .bonethug/deploy.rb sync_to --verbose"
    when 'sync-backup-from'
      exec "export to=#{environment} && bundle exec mina -f .bonethug/deploy.rb sync_from --verbose"

    when 'sync-local-to'
      exec "ruby .bonethug/syncer.rb sync_local_to #{environment}"
    when 'sync-local-from'
      exec "ruby .bonethug/syncer.rb sync_local_from #{environment}"                 
    end 

  when 'watch'

    # handle args
    type = ARGV[1] || 'coffee_sass'
    location = ARGV[2] || '.'
    watch_only = ARGV[3] || nil   
    
    # run the installer
    Watcher.watch type, location, watch_only   
  
  when 'clean'

    location = ARGV[1] || '.'
    Installer.clean location   

  else

    # We didn't find a task
    puts 'Task not found'

  end

end