Class: App42::Command::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/app42/command/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg = []) ⇒ Object



18
19
20
21
22
23
# File 'lib/app42/command/client.rb', line 18

def initialize(arg = [])
  @args = args
  @options = {}
  @should_exit = true
  @exception_msg = nil
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



14
15
16
# File 'lib/app42/command/client.rb', line 14

def args
  @args
end

#commandObject (readonly)

Returns the value of attribute command.



13
14
15
# File 'lib/app42/command/client.rb', line 13

def command
  @command
end

#kclassObject (readonly)

read access



12
13
14
# File 'lib/app42/command/client.rb', line 12

def kclass
  @kclass
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/app42/command/client.rb', line 15

def options
  @options
end

Class Method Details

.app42(*args) ⇒ Object

call for require files Initiate client object

Parameters:

  • args


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/app42/command/client.rb', line 33

def self.app42(*args )
  begin
    action = args.shift.strip rescue 'help'
    App42::Command::Client.new.load_command_file
    App42::Command::Client.new.start(action, args)
  rescue Interrupt => e 
    @exception_msg = e.message
  rescue OptionParser::MissingArgument => e
    @exception_msg = e.message
  rescue OptionParser::InvalidOption => e 
    @exception_msg = e.message
  rescue OptionParser::AmbiguousOption => e  
    @exception_msg = e.message
  rescue => error
    @exception_msg = e.message
  ensure
    puts Paint["#{@exception_msg}", :red] 
    @should_exit = true if @should_exit.nil?
    exit @should_exit   
  end

end

Instance Method Details

#execute(command) ⇒ Object

choose action respective of class



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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/app42/command/client.rb', line 121

def execute command
  case command
    when 'version'
      set_cmd(:config, :version)

    when 'list'
      set_cmd(:config, :list)

    when 'apps'
      set_cmd(:app, :apps)

    when 'deploy'
      set_cmd(:app, :deploy)

    when 'setupinfra'
      set_cmd(:app, :setup_infra)

    when 'update'
      set_cmd(:app, :update)

    when 'keys'
      set_cmd(:user, :keys)

    when 'clearkeys'
      set_cmd(:user, :clear)

    when 'addkeys'
      set_cmd(:user, :add)

    when 'scale'
      set_cmd(:app, :scale)

    when 'descale'
      set_cmd(:app, :descale)

    when 'appstate'
      set_cmd(:info, :state)

    when 'appinfo'
      set_cmd(:info, :info)

    when 'logs'  
      set_cmd(:info, :logs)
 
    when 'start'
      set_cmd(:app, :start)

    when 'stop'
      set_cmd(:app, :stop)

    when 'restart'
      set_cmd(:app, :restart)

    when 'deleteinfra'
      set_cmd(:app, :delete)

    when 'releases'
      set_cmd(:info, :releases)

    when 'iaasproviders'
      set_cmd(:config, :iaas_providers)

    when 'frameworks'
      set_cmd(:config, :frameworks)

    when 'runtimes'
      set_cmd(:config, :runtimes)

    when 'vmconfigs'
      set_cmd(:config, :memory)

    when 'app42-update'
      set_cmd(:config, :update)

    when 'supportedservices'
      set_cmd(:service, :app42pass_services)

    when 'activities'
      set_cmd(:info, :activities)  

    when 'services'
      set_cmd(:service, :services)
    
    when 'serviceinfo'
      set_cmd(:service, :info)
      
    when 'createservice'
      set_cmd(:service, :create)
      
    when 'deleteservice'
      set_cmd(:service, :delete)

    when 'startservice'
      set_cmd(:service, :start)
      
    when 'restartservice'
      set_cmd(:service, :restart)
      
    when 'stopservice'
      set_cmd(:service, :stop)

    when 'scaleservice'
      set_cmd(:service, :vscale)

    when 'descaleservice'
      set_cmd(:service, :vdescale)  

    when 'uploadbackup'
      set_cmd(:service, :uploadbackup)          

    when 'resetservicepassword'
      set_cmd(:service, :reset_pass) 
                          
    when 'bindip'
      set_cmd(:service, :service_bind)

    when 'unbindip'
      set_cmd(:service, :service_unbind)
      
    when 'bindinfo'
      set_cmd(:service, :service_bindInfo)

    when 'setupbpaas'
      set_cmd(:setup, :setup_cloud_api)

    when 'startbpaas'
      set_cmd(:setup, :start)

    when 'stopbpaas'
      set_cmd(:setup, :stop) 

    when 'restartbpaas'
      set_cmd(:setup, :restart)

    when 'upgradebpaas'
      set_cmd(:setup, :upgrade)

    when 'downgradebpaas'
      set_cmd(:setup, :downgrade)       

    when 'deletebpaas'
      set_cmd(:setup, :delete_cloud_api)

    when 'bpaasinfo'
      set_cmd(:setup, :info)

    when 'bpaassetups'
      set_cmd(:setup, :setups)

    when 'setupwordpress'
      set_cmd(:wordpress, :setup)
      
    when 'deletewordpress'
      set_cmd(:wordpress, :delete)
      
    when 'upgradewordpress'
      set_cmd(:wordpress, :upgrade)

    when 'downgradewordpress'
      set_cmd(:wordpress, :downgrade)  
      
    when 'startwordpress'
      set_cmd(:wordpress, :start)
      
    when 'stopwordpress'
      set_cmd(:wordpress, :stop)

    when 'restartwordpress'
      set_cmd(:wordpress, :restart)

    when 'wordpresssetups'
      set_cmd(:wordpress, :wordpresssetups)
      
    when 'wordpressinfo'
      set_cmd(:wordpress, :info)

    when 'addcustomurl'
      set_cmd(:app, :add_custom_url)
      
    when 'removecustomurl'
      set_cmd(:app, :remove_custom_url)
      
    when 'customurlinfo'
      set_cmd(:app, :urls)

    when 'setupgpaas'
      set_cmd(:gpaas, :setup)

    when 'startgpaas'
      set_cmd(:gpaas, :start)

    when 'stopgpaas'
      set_cmd(:gpaas, :stop)

    when 'restartgpaas'
      set_cmd(:gpaas, :restart)

    when 'upgradegpaas'
      set_cmd(:gpaas, :upgrade)

    when 'downgradegpaas'
      set_cmd(:gpaas, :downgrade)

    when 'deletegpaas'
      set_cmd(:gpaas, :delete)

    when 'gpaasinfo'
      set_cmd(:gpaas, :info)

    when 'gpaassetups'
      set_cmd(:gpaas, :setups)

    when 'assignstaticip'
      set_cmd(:app, :assign)

    when 'releasestaticip'
      set_cmd(:app, :release)

    when 'upgradegpaasdashboard'
      set_cmd(:gpaas, :update)


    else
    puts Paint["app42: Unknown command [#{action}]", :red]
    App42::Base::Help.how_to
  end
end

#helpObject

invoke help options



356
357
358
# File 'lib/app42/command/client.rb', line 356

def help
  App42::Base::Help.commands
end

#is_available?(command) ⇒ Boolean

Returns true OR false.

Returns:

  • (Boolean)

    true OR false



116
117
118
# File 'lib/app42/command/client.rb', line 116

def is_available? command
  App42::Base::APP42_COMMAND.include?(command.downcase)
end

#load_command_fileObject

pre load all commands file



26
27
28
# File 'lib/app42/command/client.rb', line 26

def load_command_file
  Dir[File.join(File.dirname(__FILE__), "*.rb")].each { |file| require file }
end

#parse_options(command, args) ⇒ Object

Collect all the available options for all commands Some duplicates exists to capture all scenarios



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
# File 'lib/app42/command/client.rb', line 58

def parse_options(command, args)
  opts_parser = OptionParser.new do |opts|
    opts.banner = "\nAvailable options:\n\n"

    opts.on('--apiKey API_KEY')         { |api|      @options[:api] = api }
    opts.on('--secretKey SECRET_KEY')   { |secret|   @options[:secret] = secret }
    opts.on('-a API_KEY')               { |api|      @options[:api] = api }
    opts.on('-s SECRET_KEY')            { |secret|   @options[:secret] = secret }

    opts.on('--app NAME')               { |name|     @options[:name] = name }
    opts.on('--name NAME')              { |name|     @options[:name] = name }

    opts.on('--instance INSTANCE')      { |instance| @options[:instance] = instance }
    opts.on('-i INSTANCE')              { |instance| @options[:instance] = instance }

    opts.on('--kontena KONTENA')        { |kontena| @options[:kontena] = kontena }
    opts.on('-i KONTENA')               { |kontena| @options[:kontena] = kontena }

    opts.on('--service SERVICE')        { |service| @options[:service] = service }
    opts.on('-s SERVICE')               { |service| @options[:service] = service }

    opts.on('--setup SETUP')            { |setup| @options[:setup] = setup }
    opts.on('-s SETUP')                 { |setup| @options[:setup] = setup }

    opts.on('--wordpress WORDPRESS')    { |setup| @options[:wordpress] = wordpress }
    opts.on('-wp WORDPRESSNAME')        { |setup| @options[:wordpress] = wordpress }

    opts.on('-h', '--help')             {            puts "#{App42::Base::Help.usage(command)}\n"; exit! }
  end
  opts_parser.parse!(args)
  self
end

#set_cmd(kclass, command) ⇒ Object

Set class and respective methods



350
351
352
353
# File 'lib/app42/command/client.rb', line 350

def set_cmd(kclass, command)
  @kclass = kclass
  @command = command
end

#start(command, args = []) ⇒ Object

Parameters:

  • command (Object)
  • args (Object) (defaults to: [])


93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/app42/command/client.rb', line 93

def start(command, args = [])
  if is_available?(command)
    parse_options(command.downcase, args)
    execute command.downcase
    cmd = App42::Command.const_get(@kclass.to_s.capitalize)
    begin
      cmd.new(@options).send(@command)
    rescue Interrupt
      puts Paint[" Command cancelled.", :red]
      exit!
    rescue Exception => e
      puts e
    end
  elsif command == 'help'
    send(command.downcase)
  else
    puts Paint["app42: Unknown command [#{command}]", :red]
    App42::Base::Help.how_to
  end
end