Class: Bricolage::GlobalOptions

Inherits:
CommonApplicationOptions show all
Defined in:
lib/bricolage/application.rb

Instance Attribute Summary collapse

Attributes inherited from CommonApplicationOptions

#parser

Instance Method Summary collapse

Methods inherited from CommonApplicationOptions

#common_options, #log_path_format, #log_s3_ds, #log_s3_key_format, #merge_saved_options, #s3_log_spec

Constructor Details

#initialize(app) ⇒ GlobalOptions

Returns a new instance of GlobalOptions.



292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/bricolage/application.rb', line 292

def initialize(app)
  @app = app
  @job_file = nil
  @environment = nil
  @home = nil
  @global_variables = Variables.new
  @dry_run = false
  @explain = false
  @list_global_variables = false
  @list_variables = false
  @list_declarations = false
  @dump_options = false
  init_options
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



383
384
385
# File 'lib/bricolage/application.rb', line 383

def environment
  @environment
end

#global_variablesObject (readonly)

Returns the value of attribute global_variables.



404
405
406
# File 'lib/bricolage/application.rb', line 404

def global_variables
  @global_variables
end

#homeObject (readonly)

Returns the value of attribute home.



384
385
386
# File 'lib/bricolage/application.rb', line 384

def home
  @home
end

#job_fileObject (readonly)

Returns the value of attribute job_file.



386
387
388
# File 'lib/bricolage/application.rb', line 386

def job_file
  @job_file
end

Instance Method Details

#define_options(parser) ⇒ Object



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
# File 'lib/bricolage/application.rb', line 311

def define_options(parser)
  parser.banner = <<-EndBanner
Synopsis:
  #{@app.program_name} [global_options] JOB_CLASS [job_options]
  #{@app.program_name} [global_options] --job=JOB_FILE -- [job_options]
Global Options:
  EndBanner
  parser.on('-f', '--job=JOB_FILE', 'Give job parameters via job file (YAML).') {|path|
    @job_file = path
  }
  parser.on('-e', '--environment=NAME', "Sets execution environment [default: #{Context::DEFAULT_ENV}]") {|env|
    @environment = env
  }
  parser.on('-C', '--home=PATH', 'Sets application home directory.') {|path|
    @home = Pathname(path)
  }
  parser.on('-n', '--dry-run', 'Shows job script without executing it.') {
    @dry_run = true
  }
  parser.on('-E', '--explain', 'Applies EXPLAIN to the SQL.') {
    @explain = true
  }

  define_common_options

  parser.on('--list-job-class', 'Lists job class name and (internal) class path.') {
    JobClass.list.each do |name|
      puts name
    end
    exit 0
  }
  parser.on('--list-global-variables', 'Lists global variables.') {
    @list_global_variables = true
  }
  parser.on('--list-variables', 'Lists all variables.') {
    @list_variables = true
  }
  parser.on('--list-declarations', 'Lists script variable declarations.') {
    @list_declarations = true
  }
  parser.on('-r', '--require=FEATURE', 'Requires ruby library.') {|feature|
    require feature
  }
  parser.on('-v', '--variable=NAME=VALUE', 'Set global variable (is different from job-level -v !!).') {|name_value|
    name, value = name_value.split('=', 2)
    @global_variables[name] = value
  }
  parser.on('--dump-options', 'Shows option parsing result and quit.') {
    @dump_options = true
  }
  parser.on('--help', 'Shows this message and quit.') {
    puts parser.help
    exit 0
  }
  parser.on('--version', 'Shows program version and quit.') {
    puts "#{APPLICATION_NAME} version #{VERSION}"
    exit 0
  }
end

#dry_run?Boolean

Returns:

  • (Boolean)


392
393
394
# File 'lib/bricolage/application.rb', line 392

def dry_run?
  @dry_run
end

#dump_options?Boolean

Returns:

  • (Boolean)


400
401
402
# File 'lib/bricolage/application.rb', line 400

def dump_options?
  @dump_options
end

#explain?Boolean

Returns:

  • (Boolean)


396
397
398
# File 'lib/bricolage/application.rb', line 396

def explain?
  @explain
end

#file_mode?Boolean

Returns:

  • (Boolean)


388
389
390
# File 'lib/bricolage/application.rb', line 388

def file_mode?
  !!@job_file
end

#helpObject



307
308
309
# File 'lib/bricolage/application.rb', line 307

def help
  @parser.help
end

#list_declarations?Boolean

Returns:

  • (Boolean)


414
415
416
# File 'lib/bricolage/application.rb', line 414

def list_declarations?
  @list_declarations
end

#list_global_variables?Boolean

Returns:

  • (Boolean)


406
407
408
# File 'lib/bricolage/application.rb', line 406

def list_global_variables?
  @list_global_variables
end

#list_variables?Boolean

Returns:

  • (Boolean)


410
411
412
# File 'lib/bricolage/application.rb', line 410

def list_variables?
  @list_variables
end

#on(*args, &block) ⇒ Object



371
372
373
# File 'lib/bricolage/application.rb', line 371

def on(*args, &block)
  @parser.on(*args, &block)
end

#option_pairsObject



418
419
420
421
422
423
# File 'lib/bricolage/application.rb', line 418

def option_pairs
  common_options.merge({
    'environment' => OptionValue.new(nil, @environment),
    'home' => OptionValue.new(nil, @home)
  })
end

#parse!(argv) ⇒ Object



375
376
377
378
379
380
381
# File 'lib/bricolage/application.rb', line 375

def parse!(argv)
  @parser.order! argv
  @rest_args = argv.dup
  build_common_options!
rescue OptionParser::ParseError => ex
  raise OptionError, ex.message
end