Class: Warg::Context

Inherits:
Config show all
Defined in:
lib/warg.rb

Defined Under Namespace

Classes: Playlist

Instance Attribute Summary collapse

Attributes inherited from Config

#default_user, #hosts, #variables_sets

Instance Method Summary collapse

Methods inherited from Config

#[], #variables, #variables_set_defined?

Constructor Details

#initialize(argv) ⇒ Context

Returns a new instance of Context.



1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
# File 'lib/warg.rb', line 1382

def initialize(argv)
  @argv = argv
  @parser = OptionParser.new
  @playlist = Playlist.new

  @parser.on("-t", "--target HOSTS", Array, "hosts to use") do |hosts_data|
    hosts_data.each { |host_data| hosts.add(host_data) }
  end

  super()
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



1379
1380
1381
# File 'lib/warg.rb', line 1379

def argv
  @argv
end

#parserObject (readonly)

Returns the value of attribute parser.



1380
1381
1382
# File 'lib/warg.rb', line 1380

def parser
  @parser
end

Instance Method Details

#copy(config) ⇒ Object



1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
# File 'lib/warg.rb', line 1408

def copy(config)
  config.hosts.each do |host|
    hosts.add(host)
  end

  config.variables_sets.each do |variables_name|
    variables(variables_name) do |variables_object|
      variables_object.copy config.instance_variable_get("@#{variables_name}")
    end
  end
end

#parse_options!Object



1394
1395
1396
# File 'lib/warg.rb', line 1394

def parse_options!
  @parser.parse(@argv)
end

#queue!(command) ⇒ Object



1398
1399
1400
# File 'lib/warg.rb', line 1398

def queue!(command)
  @playlist.queue(command)
end

#run!Object



1402
1403
1404
1405
1406
# File 'lib/warg.rb', line 1402

def run!
  Console.hostname_width = hosts.map { |host| host.address.length }.max

  @playlist.start
end