Class: VMC::Cli::Runner

Inherits:
Object show all
Defined in:
lib/cli/usage.rb,
lib/cli/runner.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = []) ⇒ Runner

Returns a new instance of Runner.



17
18
19
20
21
# File 'lib/cli/runner.rb', line 17

def initialize(args=[])
  @args = args
  @options = { :colorize => true }
  @exit_status = true
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



9
10
11
# File 'lib/cli/runner.rb', line 9

def action
  @action
end

#argsObject (readonly)

Returns the value of attribute args.



10
11
12
# File 'lib/cli/runner.rb', line 10

def args
  @args
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



8
9
10
# File 'lib/cli/runner.rb', line 8

def namespace
  @namespace
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/cli/runner.rb', line 11

def options
  @options
end

Class Method Details

.run(args) ⇒ Object



13
14
15
# File 'lib/cli/runner.rb', line 13

def self.run(args)
  new(args).run
end

Instance Method Details

#basic_usageObject



3
4
5
6
# File 'lib/cli/usage.rb', line 3

def basic_usage
  "Usage: olympe [options] command [<args>] [command_options]\n" +
  "Try 'olympe help [command]' or 'olympe help options' for more information."
end

#check_instances_delta!Object



114
115
116
117
118
119
# File 'lib/cli/runner.rb', line 114

def check_instances_delta!
  return unless @args
  instance_args = @args.select { |arg| /^[-]\d+$/ =~ arg } || []
  @args.delete_if { |arg| instance_args.include? arg}
  instance_args
end

#command_usageObject



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
# File 'lib/cli/usage.rb', line 20

def command_usage
  <<-USAGE

#{basic_usage}

Currently available olympe commands are:

Getting Started
  target [url]                                 Reports current target or sets a new target
  login  [email] [--email, --passwd]           Login
  info                                         System and account information

Applications
  apps                                         List deployed applications

Application Creation
  push [appname]                               Create, push, map, and start a new application
  push [appname] --infra                       Push application to specified infrastructure
  push [appname] --path                        Push application from specified path
  push [appname] --url                         Set the url for the application
  push [appname] --instances <N>               Set the expected number <N> of instances
  push [appname] --mem M                       Set the memory reservation for the application
  push [appname] --runtime RUNTIME             Set the runtime to use for the application
  push [appname] --debug [MODE]                Push application and start in a debug mode
  push [appname] --no-start                    Do not auto-start the application

Application Operations
  start <appname> [--debug [MODE]]             Start the application
  stop  <appname>                              Stop the application
  restart <appname> [--debug [MODE]]           Restart the application
  delete <appname>                             Delete the application
  clone <src-app> <dest-app> [infra]           Clone the application and services

Application Updates
  update <appname> [--path,--debug [MODE]]     Update the application bits
  mem <appname> [memsize]                      Update the memory reservation for an application
  map <appname> <url>                          Register the application to the url
  unmap <appname> <url>                        Unregister the application from the url
  instances <appname> <num|delta>              Scale the application instances up or down

Application Information
  crashes <appname>                            List recent application crashes
  crashlogs <appname>                          Display log information for crashed applications
  logs <appname> [--all]                       Display log information for the application
  files <appname> [path] [--all]               Display directory listing or file download for [path]
  stats <appname>                              Display resource usage for the application
  instances <appname>                          List application instances
  
Application Download
  pull <appname> [path]                        Downloads last pushed source to <appname> or [path]
  download <appname> [path]                    Downloads last pushed source to zipfile

Application Environment
  env <appname>                                List application environment variables
  env-add <appname> <variable[=]value>         Add an environment variable to an application
  env-del <appname> <variable>                 Delete an environment variable to an application

Services
  services                                     Lists of services available and provisioned
  create-service <service> [--name,--bind]     Create a provisioned service
  create-service <service> --infra     		     Create a provisioned service on a specified infrastructure
  create-service <service> <name>              Create a provisioned service and assign it <name>
  create-service <service> <name> <app>        Create a provisioned service and assign it <name>, and bind to <app>
  delete-service [servicename]                 Delete a provisioned service
  bind-service <servicename> <appname>         Bind a service to an application
  unbind-service <servicename> <appname>       Unbind service from the application
  clone-services <src-app> <dest-app>          Clone service bindings from <src-app> application to <dest-app>
  export-service <service>                     Export the data from a service
  import-service <service> <url>               Import data into a service
  tunnel <servicename> [--port]                Create a local tunnel to a service
  tunnel <servicename> <clientcmd>             Create a local tunnel to a service and start a local client

Administration
  user                                         Display user account information
  passwd                                       Change the password for the current user
  logout                                       Logs current user out of the target system
  add-user [--email, --passwd]                 Register a new user (requires admin privileges)
  delete-user <user>                           Delete a user and all apps and services (requires admin privileges)

System
  runtimes                                     Display the supported runtimes of the target system
  frameworks                                   Display the recognized frameworks of the target system
  infras                                       Display the available infrastructures

Micro Cloud Foundry
  micro status                                 Display Micro Cloud Foundry VM status
  micro offline                                Configure Micro Cloud Foundry VM for offline mode
  micro online                                 Configure Micro Cloud Foundry VM for online mode
    [--vmx file]                               Path to micro.vmx
    [--vmrun executable]                       Path to vmrun executable
    [--password cleartext]                     Cleartext password for guest VM vcap user
    [--save]                                   Save cleartext password in ~/.olympe_micro

Misc
  aliases                                      List aliases
  alias <alias[=]command>                      Create an alias for a command
  unalias <alias>                              Remove an alias
  targets                                      List known targets and associated authorization tokens

Help
  help [command]                               Get general help or help on a specific command
  help options                                 Get help on available options
USAGE

end

#convert_options!Object



126
127
128
129
# File 'lib/cli/runner.rb', line 126

def convert_options!
  # make sure certain options are valid and in correct form.
  @options[:instances] = Integer(@options[:instances]) if @options[:instances]
end

#display_helpObject



121
122
123
124
# File 'lib/cli/runner.rb', line 121

def display_help
  puts command_usage
  exit
end

#display_usageObject



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/cli/usage.rb', line 8

def display_usage
  if @usage
    say @usage_error if @usage_error
    say "Usage: #{@usage}"
    return
  elsif @verb_usage
    say @verb_usage
    return
  end
  say command_usage
end

#parse_command!Object



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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
# File 'lib/cli/runner.rb', line 150

def parse_command!
  # just return if already set, happends with -v, -h
  return if @namespace && @action

  verb = @args.shift
  case verb

  when 'version'
    usage('olympe version')
    set_cmd(:misc, :version)

  when 'target'
    usage('olympe target [url] [--url]')
    if @args.size == 1
      set_cmd(:misc, :set_target, 1)
    else
      set_cmd(:misc, :target)
    end

  when 'targets'
    usage('olympe targets')
    set_cmd(:misc, :targets)

  when 'tokens'
    usage('olympe tokens')
    set_cmd(:misc, :tokens)

  when 'info'
    usage('olympe info')
    set_cmd(:misc, :info)

  when 'runtimes'
    usage('olympe runtimes')
    set_cmd(:misc, :runtimes)

  when 'frameworks'
    usage('olympe frameworks')
    set_cmd(:misc, :frameworks)

  when 'infras'
    usage('olympe infras')
    set_cmd(:misc, :infras)

  when 'user'
    usage('olympe user')
    set_cmd(:user, :info)

  when 'login'
    usage('olympe login [email] [--email EMAIL] [--passwd PASS]')
    if @args.size == 1
      set_cmd(:user, :login, 1)
    else
      set_cmd(:user, :login)
    end

  when 'logout'
    usage('olympe logout')
    set_cmd(:user, :logout)

  when 'passwd'
    usage('olympe passwd')
    if @args.size == 1
      set_cmd(:user, :change_password, 1)
    else
      set_cmd(:user, :change_password)
    end

  when 'add-user', 'add_user', 'create_user', 'create-user', 'register'
    usage('olympe add-user [user] [--email EMAIL] [--passwd PASS]')
    if @args.size == 1
      set_cmd(:admin, :add_user, 1)
    else
      set_cmd(:admin, :add_user)
    end

  when 'delete-user', 'delete_user', 'unregister'
    usage('olympe delete-user <user>')
    set_cmd(:admin, :delete_user, 1)

  when 'users'
    usage('olympe users')
    set_cmd(:admin, :users)

  when 'apps'
    usage('olympe apps')
    set_cmd(:apps, :apps)

  when 'list'
    usage('olympe list')
    set_cmd(:apps, :list)

  when 'start'
    usage('olympe start <appname>')
    set_cmd(:apps, :start, @args.size == 1 ? 1 : 0)

  when 'stop'
    usage('olympe stop <appname>')
    set_cmd(:apps, :stop, @args.size == 1 ? 1 : 0)

  when 'restart'
    usage('olympe restart <appname>')
    set_cmd(:apps, :restart, @args.size == 1 ? 1 : 0)

  when 'mem'
    usage('olympe mem <appname> [memsize]')
    if @args.size == 2
      set_cmd(:apps, :mem, 2)
    else
      set_cmd(:apps, :mem, 1)
    end

  when 'stats'
    usage('olympe stats <appname>')
    set_cmd(:apps, :stats, @args.size == 1 ? 1 : 0)

  when 'map'
    usage('olympe map <appname> <url>')
    set_cmd(:apps, :map, 2)

  when 'unmap'
    usage('olympe unmap <appname> <url>')
    set_cmd(:apps, :unmap, 2)

  when 'delete'
    usage('olympe delete <appname>')
    if @options[:all] && @args.size == 0
      set_cmd(:apps, :delete)
    else
      set_cmd(:apps, :delete, 1)
    end

  when 'files'
    usage('olympe files <appname> [path] [--instance N] [--all] [--prefix]')
    if @args.size == 1
      set_cmd(:apps, :files, 1)
    else
      set_cmd(:apps, :files, 2)
    end
    
  when 'download'
    usage('olympe download <appname> [path]')
    if @args.size == 1
      set_cmd(:apps, :download, 1)
    else
      set_cmd(:apps, :download, 2)
    end
    
  when 'pull'
    usage('olympe pull <appname> [path]')
    if @args.size == 1
      set_cmd(:apps, :pull, 1)
    else
      set_cmd(:apps, :pull, 2)
    end

  when 'logs'
    usage('olympe logs <appname> [--instance N] [--all] [--prefix]')
    set_cmd(:apps, :logs, 1)

  when 'instances', 'scale'
    if @args.size > 1
      usage('olympe instances <appname> <num|delta>')
      set_cmd(:apps, :instances, 2)
    else
      usage('olympe instances <appname>')
      set_cmd(:apps, :instances, 1)
    end

  when 'crashes'
    usage('olympe crashes <appname>')
    set_cmd(:apps, :crashes, 1)

  when 'crashlogs'
    usage('olympe crashlogs <appname>')
    set_cmd(:apps, :crashlogs, 1)

  when 'push'
    usage('olympe push [appname] [--path PATH] [--url URL] [--instances N] [--mem] [--runtime RUNTIME] [--no-start] [--infra infraname]')
    if @args.size == 1
      set_cmd(:apps, :push, 1)
    else
      set_cmd(:apps, :push, 0)
    end

  when 'update'
    usage('olympe update <appname> [--path PATH]')
    set_cmd(:apps, :update, @args.size == 1 ? 1 : 0)

  when 'services'
    usage('olympe services')
    set_cmd(:services, :services)

  when 'env'
    usage('olympe env <appname>')
    set_cmd(:apps, :environment, 1)

  when 'env-add'
    usage('olympe env-add <appname> <variable[=]value>')
    if @args.size == 2
      set_cmd(:apps, :environment_add, 2)
    elsif @args.size == 3
      set_cmd(:apps, :environment_add, 3)
    end

  when 'env-del'
    usage('olympe env-del <appname> <variable>')
    set_cmd(:apps, :environment_del, 2)

  when 'create-service', 'create_service'
    usage('olympe create-service [service] [servicename] [appname] [--name servicename] [--bind appname] [--infra infraname]')
    set_cmd(:services, :create_service) if @args.size == 0
    set_cmd(:services, :create_service, 1) if @args.size == 1
    set_cmd(:services, :create_service, 2) if @args.size == 2
    set_cmd(:services, :create_service, 3) if @args.size == 3

  when 'delete-service', 'delete_service'
    usage('olympe delete-service <service>')
    if @args.size == 1
      set_cmd(:services, :delete_service, 1)
    else
      set_cmd(:services, :delete_service)
    end

  when 'bind-service', 'bind_service'
    usage('olympe bind-service <servicename> <appname>')
    set_cmd(:services, :bind_service, 2)

  when 'unbind-service', 'unbind_service'
    usage('olympe unbind-service <servicename> <appname>')
    set_cmd(:services, :unbind_service, 2)

  when 'clone-services'
    usage('olympe clone-services <src-app> <dest-app>')
    set_cmd(:services, :clone_services, 2)

  when 'export-service'
    usage('olympe export-service <service-name>')
    set_cmd(:services, :export_service, 1)
    
  when 'import-service'
    usage('olympe import-service <service-name> <url>')
    set_cmd(:services, :import_service, 2)
    
  when 'clone'
    usage('olympe clone <src-app> <dest-app> [<infra>]')
    set_cmd(:apps, :clone, 2) if @args.size == 2
    set_cmd(:apps, :clone, 3) if @args.size == 3
    
  when 'aliases'
    usage('olympe aliases')
    set_cmd(:misc, :aliases)

  when 'alias'
    usage('olympe alias <alias[=]command>')
    if @args.size == 1
      set_cmd(:misc, :alias, 1)
    elsif @args.size == 2
      set_cmd(:misc, :alias, 2)
    end

  when 'unalias'
    usage('olympe unalias <alias>')
    set_cmd(:misc, :unalias, 1)

  when 'tunnel'
    usage('olympe tunnel [servicename] [clientcmd] [--port port]')
    set_cmd(:services, :tunnel, 0) if @args.size == 0
    set_cmd(:services, :tunnel, 1) if @args.size == 1
    set_cmd(:services, :tunnel, 2) if @args.size == 2

  when 'rails-console'
    usage('olympe rails-console <appname>')
    set_cmd(:apps, :console, 1)

  when 'micro'
    usage('olympe micro <online|offline|status> [--password password] [--save] [--vmx file] [--vmrun executable]')
    if %w[online offline status].include?(@args[0])
        set_cmd(:micro, @args[0].to_sym, 1)
    end

  when 'help'
    display_help if @args.size == 0
    @help_only = true
    parse_command!

  when 'usage'
    display basic_usage
    exit(true)

  when 'options'
    # Simulate --options
    @args = @args.unshift('--options')
    parse_options!

  when 'manifest'
    usage('olympe manifest')
    set_cmd(:manifest, :edit)

  when 'extend-manifest'
    usage('olympe extend-manifest')
    set_cmd(:manifest, :extend, 1)

  else
    if verb
      display "olympe: Unknown command [#{verb}]"
      display basic_usage
      exit(false)
    end
  end
end

#parse_options!Object

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



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
# File 'lib/cli/runner.rb', line 25

def parse_options!
  opts_parser = OptionParser.new do |opts|
    opts.banner = "\nAvailable options:\n\n"

    opts.on('--email EMAIL')     { |email| @options[:email] = email }
    opts.on('--user EMAIL')      { |email| @options[:email] = email }
    opts.on('--passwd PASS')     { |pass|  @options[:password] = pass }
    opts.on('--pass PASS')       { |pass|  @options[:password] = pass }
    opts.on('--password PASS')   { |pass|  @options[:password] = pass }
    opts.on('--token-file TOKEN_FILE')     { |token_file|  @options[:token_file] = token_file }
    opts.on('--app NAME')        { |name|  @options[:name] = name }
    opts.on('--name NAME')       { |name|  @options[:name] = name }
    opts.on('--bind BIND')       { |bind|  @options[:bind] = bind }
    opts.on('--instance INST')   { |inst|  @options[:instance] = inst }
    opts.on('--instances INST')  { |inst|  @options[:instances] = inst }
    opts.on('--url URL')         { |url|   @options[:url] = url }
    opts.on('--mem MEM')         { |mem|   @options[:mem] = mem }
    opts.on('--path PATH')       { |path|  @options[:path] = path }
    opts.on('--no-start')        {         @options[:nostart] = true }
    opts.on('--nostart')         {         @options[:nostart] = true }
    opts.on('--force')           {         @options[:force] = true }
    opts.on('--all')             {         @options[:all] = true }

    # generic tracing and debugging
    opts.on('-t [TKEY]')         { |tkey|  @options[:trace] = tkey || true }
    opts.on('--trace [TKEY]')    { |tkey|  @options[:trace] = tkey || true }

    # start application in debug mode
    opts.on('-d [MODE]')         { |mode|  @options[:debug] = mode || "run" }
    opts.on('--debug [MODE]')    { |mode|  @options[:debug] = mode || "run" }

    # override manifest file
    opts.on('-m FILE')           { |file|  @options[:manifest] = file }
    opts.on('--manifest FILE')   { |file|  @options[:manifest] = file }

    opts.on('-q', '--quiet')     {         @options[:quiet] = true }

    # micro cloud options
    opts.on('--vmx FILE')        { |file|  @options[:vmx] = file }
    opts.on('--vmrun FILE')      { |file|  @options[:vmrun] = file }
    opts.on('--save')            {         @options[:save] = true }

    # Don't use builtin zip
    opts.on('--no-zip')          {         @options[:nozip] = true }
    opts.on('--nozip')           {         @options[:nozip] = true }

    opts.on('--no-resources')    {         @options[:noresources] = true }
    opts.on('--noresources')     {         @options[:noresources] = true }

    opts.on('--no-color')        {         @options[:colorize] = false }
    opts.on('--verbose')         {         @options[:verbose] = true }

    opts.on('-n','--no-prompt')  {         @options[:noprompts] = true }
    opts.on('--noprompt')        {         @options[:noprompts] = true }
    opts.on('--non-interactive') {         @options[:noprompts] = true }

    opts.on('--prefix')          {         @options[:prefixlogs] = true }
    opts.on('--prefix-logs')     {         @options[:prefixlogs] = true }
    opts.on('--prefixlogs')      {         @options[:prefixlogs] = true }

    opts.on('--json')            {         @options[:json] = true }

    opts.on('-v', '--version')   {         set_cmd(:misc, :version) }
    opts.on('-h', '--help')      {         puts "#{command_usage}\n"; exit }

    opts.on('--port PORT')       { |port|  @options[:port] = port }

    opts.on('--runtime RUNTIME') { |rt|    @options[:runtime] = rt }

    # deprecated
    opts.on('--exec EXEC')       { |exec|  @options[:exec] = exec }
    opts.on('--noframework')     {         @options[:noframework] = true }
    opts.on('--canary')          {         @options[:canary] = true }

    # Proxying for another user, requires admin privileges
    opts.on('-u PROXY')          { |proxy| @options[:proxy] = proxy }
    
    # Select infrastructure
    opts.on('--infra INFRA')     { |infra| @options[:infra] = infra }

    opts.on_tail('--options')    {          puts "#{opts}\n"; exit }
  end
  instances_delta_arg = check_instances_delta!
  @args = opts_parser.parse!(@args)
  @args.concat instances_delta_arg
  convert_options!
  self
end

#process_aliases!Object



461
462
463
464
465
466
467
468
469
470
471
# File 'lib/cli/runner.rb', line 461

def process_aliases!
  return if @args.empty?
  aliases = VMC::Cli::Config.aliases
  aliases.each_pair do |k,v|
    if @args[0] == k
      display "[#{@args[0]} aliased to #{aliases.invert[key]}]" if @options[:verbose]
      @args[0] = v
      break;
    end
  end
end

#runObject



483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
# File 'lib/cli/runner.rb', line 483

def run

  trap('TERM') { print "\nTerminated\n"; exit(false)}

  parse_options!

  @options[:colorize] = false unless STDOUT.tty?

  VMC::Cli::Config.colorize   = @options.delete(:colorize)
  VMC::Cli::Config.nozip      = @options.delete(:nozip)
  VMC::Cli::Config.trace      = @options.delete(:trace)
  VMC::Cli::Config.output   ||= STDOUT unless @options[:quiet]
  VMC::Cli::Config.infra      = @options[:infra]

  process_aliases!
  parse_command!

  if @namespace && @action
    cmd = VMC::Cli::Command.const_get(@namespace.to_s.capitalize)
    cmd.new(@options).send(@action, *@args.collect(&:dup))
  elsif @help_only || @usage
    display_usage
  else
    display basic_usage
    exit(false)
  end

rescue OptionParser::InvalidOption => e
  puts(e.message.red)
  puts("\n")
  puts(basic_usage)
  @exit_status = false
rescue OptionParser::AmbiguousOption => e
  puts(e.message.red)
  puts("\n")
  puts(basic_usage)
  @exit_status = false
rescue VMC::Client::AuthError => e
  if VMC::Cli::Config.auth_token.nil?
    puts "Login Required".red
  else
    puts "Not Authorized".red
  end
  @exit_status = false
rescue VMC::Client::TargetError, VMC::Client::NotFound, VMC::Client::BadTarget  => e
  puts e.message.red
  @exit_status = false
rescue VMC::Client::HTTPException => e
  puts e.message.red
  @exit_status = false
rescue VMC::Cli::GracefulExit => e
  # Redirected commands end up generating this exception (kind of goto)
rescue VMC::Cli::CliExit => e
  puts e.message.red
  @exit_status = false
rescue VMC::Cli::CliError => e
  say("Error #{e.error_code}: #{e.message}".red)
  @exit_status = false
rescue SystemExit => e
  @exit_status = e.success?
rescue SyntaxError => e
  puts e.message.red
  puts e.backtrace
  @exit_status = false
rescue Interrupt => e
  say("\nInterrupted".red)
  @exit_status = false
rescue Exception => e
  puts e.message.red
  puts e.backtrace
  @exit_status = false
ensure
  say("\n")
  @exit_status == true if @exit_status.nil?
  if @options[:verbose]
    if @exit_status
      puts "[#{@namespace}:#{@action}] SUCCEEDED".green
    else
      puts "[#{@namespace}:#{@action}] FAILED".red
    end
    say("\n")
  end
  exit(@exit_status)
end

#set_cmd(namespace, action, args_range = 0) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/cli/runner.rb', line 131

def set_cmd(namespace, action, args_range=0)
  return if @help_only
  unless args_range == "*" || args_range.is_a?(Range)
    args_range = (args_range.to_i..args_range.to_i)
  end

  if args_range == "*" || args_range.include?(@args.size)
    @namespace = namespace
    @action    = action
  else
    @exit_status = false
    if @args.size > args_range.last
      usage_error("Too many arguments for [#{action}]: %s" % [ @args[args_range.last..-1].map{|a| "'#{a}'"}.join(', ') ])
    else
      usage_error("Not enough arguments for [#{action}]")
    end
  end
end

#usage(msg = nil) ⇒ Object



473
474
475
476
# File 'lib/cli/runner.rb', line 473

def usage(msg = nil)
  @usage = msg if msg
  @usage
end

#usage_error(msg = nil) ⇒ Object



478
479
480
481
# File 'lib/cli/runner.rb', line 478

def usage_error(msg = nil)
  @usage_error = msg if msg
  @usage_error
end