Class: Bricolage::JobNetRunner::Options

Inherits:
CommonApplicationOptions show all
Defined in:
lib/bricolage/jobnetrunner.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) ⇒ Options

Returns a new instance of Options.



211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/bricolage/jobnetrunner.rb', line 211

def initialize(app)
  @app = app
  @environment = nil
  @global_variables = Variables.new
  @jobnet_files = nil

  @dump_options = false
  @check_only = false
  @list_jobs = false
  @clear_queue = false

  init_options
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



316
317
318
# File 'lib/bricolage/jobnetrunner.rb', line 316

def environment
  @environment
end

#global_variablesObject (readonly)

Returns the value of attribute global_variables.



320
321
322
# File 'lib/bricolage/jobnetrunner.rb', line 320

def global_variables
  @global_variables
end

#jobnet_filesObject (readonly)

Returns the value of attribute jobnet_files.



318
319
320
# File 'lib/bricolage/jobnetrunner.rb', line 318

def jobnet_files
  @jobnet_files
end

Instance Method Details

#check_only?Boolean

Returns:

  • (Boolean)


326
327
328
# File 'lib/bricolage/jobnetrunner.rb', line 326

def check_only?
  @check_only
end

#clear_queue?Boolean

Returns:

  • (Boolean)


355
356
357
# File 'lib/bricolage/jobnetrunner.rb', line 355

def clear_queue?
  @clear_queue
end

#define_options(parser) ⇒ Object



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

def define_options(parser)
  parser.banner = <<-EndBanner
Synopsis:
  #{@app.program_name} [options] JOB_NET_FILE
Options:
  EndBanner
  parser.on('-e', '--environment=NAME', "Sets execution environment. [default: #{Context::DEFAULT_ENV}]") {|env|
    @environment = env
  }

  define_common_options

  parser.on('--local-state-dir=PATH', 'Stores local state in this path.') {|path|
    @opts_cmdline['local-state-dir'] = OptionValue.new('--local-state-dir option', path)
  }
  parser.on('-Q', '--enable-queue', 'Enables job queue.') {
    @opts_cmdline['enable-queue'] = OptionValue.new('--enable-queue option', true)
  }
  parser.on('--disable-queue', 'Disables job queue.') {
    @opts_cmdline['enable-queue'] = OptionValue.new('--disable-queue option', false)
  }
  parser.on('--clear-queue', 'Clears job queue and quit.') {
    @clear_queue = true
  }
  parser.on('--queue-path=PATH', 'Enables job queue with this path.') {|path|
    @opts_cmdline['queue-path'] = OptionValue.new('--queue-path option', path)
  }
  parser.on('-c', '--check-only', 'Checks job parameters and quit without executing.') {
    @check_only = true
  }
  parser.on('-l', '--list-jobs', 'Lists target jobs without executing.') {
    @list_jobs = true
  }
  parser.on('-v', '--variable=NAME=VALUE', 'Defines global variable.') {|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.') {
    @app.puts parser.help
    @app.exit 0
  }
  parser.on('--version', 'Shows program version and quit.') {
    @app.puts "#{APPLICATION_NAME} version #{VERSION}"
    @app.exit 0
  }
end

#dump_options?Boolean

Returns:

  • (Boolean)


322
323
324
# File 'lib/bricolage/jobnetrunner.rb', line 322

def dump_options?
  @dump_options
end

#enable_queue?Boolean

Returns:

  • (Boolean)


341
342
343
344
# File 'lib/bricolage/jobnetrunner.rb', line 341

def enable_queue?
  opt = @opts['enable-queue']
  opt.value
end

#helpObject



249
250
251
# File 'lib/bricolage/jobnetrunner.rb', line 249

def help
  @parser.help
end

#list_jobs?Boolean

Returns:

  • (Boolean)


330
331
332
# File 'lib/bricolage/jobnetrunner.rb', line 330

def list_jobs?
  @list_jobs
end

#local_state_dirObject



334
335
336
337
338
339
# File 'lib/bricolage/jobnetrunner.rb', line 334

def local_state_dir
  @local_state_dir ||= begin
    opt = @opts['local-state-dir']
    Pathname(opt.value)
  end
end

#on(*args, &block) ⇒ Object



303
304
305
# File 'lib/bricolage/jobnetrunner.rb', line 303

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

#option_pairsObject



359
360
361
362
363
# File 'lib/bricolage/jobnetrunner.rb', line 359

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

#parse!(argv) ⇒ Object



307
308
309
310
311
312
313
314
# File 'lib/bricolage/jobnetrunner.rb', line 307

def parse!(argv)
  @parser.parse!(argv)
  raise OptionError, "missing jobnet file" if argv.empty?
  @jobnet_files = argv.map {|path| Pathname(path) }
  build_common_options!
rescue OptionParser::ParseError => ex
  raise OptionError, ex.message
end

#queue_pathObject



346
347
348
349
350
351
352
353
# File 'lib/bricolage/jobnetrunner.rb', line 346

def queue_path
  opt = @opts['queue-path']
  if opt.value
    Pathname(opt.value)
  else
    nil
  end
end