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
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
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
|
# File 'lib/galaxy.rb', line 417
def self.parse_command_line(args)
options = INITIAL_OPTIONS
filter = Hash.new{[]}
option_parser = OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename($0)} [options] <command>"
opts.separator ''
opts.separator 'Options:'
opts.on('-h', '--help', 'Display this screen') do
puts opts
exit EXIT_CODES[:success]
end
opts.on("-v", "--version", "Display the Galaxy version number and exit") do
puts "Galaxy version #{GALAXY_VERSION}"
exit EXIT_CODES[:success]
end
opts.on("--coordinator COORDINATOR", "Galaxy coordinator host (overrides GALAXY_COORDINATOR)") do |v|
options[:coordinator_url] = v
end
opts.on('--debug', 'Enable debug messages') do
options[:debug] = true
end
opts.separator ''
opts.separator 'Filters:'
opts.on("-b", "--binary BINARY", "Select slots with a given binary") do |arg|
filter[:binary] <<= arg
end
opts.on("-c", "--config CONFIG", "Select slots with given configuration") do |arg|
filter[:config] <<= arg
end
opts.on("-i", "--host HOST", "Select slots on the given hostname") do |arg|
filter[:host] <<= arg
end
opts.on("-I", "--ip IP", "Select slots at the given IP address") do |arg|
filter[:ip] <<= arg
end
opts.on("-u", "--uuid SLOT_UUID", "Select slots with given slot uuid") do |arg|
filter[:uuid] <<= arg
end
opts.on("--count count", "Number of instances to install or agents to provision") do |arg|
options[:count] = arg
end
opts.on("--availability-zone AVAILABILITY_ZONE", "Availability zone to agent provisioning") do |arg|
options[:availability_zone] = arg
end
opts.on("-x", "--ssh-command SSH_COMMAND", "Command to execute with ssh") do |arg|
options[:ssh_command] = arg
end
opts.on("-s", "--state STATE", "Select 'r{unning}', 's{topped}' or 'unknown' slots", [:running, :r, :stopped, :s, :unknown]) do |arg|
case arg
when :running, :r then
filter[:state] <<= 'running'
when :stopped, :s then
filter[:state] <<= 'stopped'
when :unknown then
filter[:state] <<= 'unknown'
end
end
opts.separator ''
opts.separator <<-NOTES
Notes:
- A filter is required for all commands except for show
- Filters are evaluated as: set | host | ip | state | (binary & config)
- The HOST, BINARY, and CONFIG arguments are globs
- BINARY format is groupId:artifactId[:packaging[:classifier]]:version
- CONFIG format is @env:component[:pools]:version
- The default filter selects all hosts
NOTES
opts.separator ''
opts.separator 'Commands:'
opts.separator " #{COMMANDS.join("\n ")}"
end
option_parser.parse!(args)
puts options.map { |k, v| "#{k}=#{v}" }.join("\n") if options[:debug]
puts filter.map { |k, v| v.map { |v1| "#{k}=#{URI.escape(v1)}" }.join('\n') }.join('\n') if options[:debug]
if args.length == 0 then
puts option_parser
exit EXIT_CODES[:success]
end
args[0] = args[0].gsub('-', '_');
command = args[0].to_sym
is_agent = false
if command == :agent then
args = args.drop(1)
if args.length == 0 then
puts option_parser
exit EXIT_CODES[:success]
end
command = "#{command}_#{args[0]}".to_sym
is_agent = true
end
unless COMMANDS.include?(command)
raise CommandError.new(:invalid_usage, "Unsupported command: #{command}")
end
if options[:coordinator_url].nil? || options[:coordinator_url].empty?
raise CommandError.new(:invalid_usage, "You must set Galaxy coordinator host by passing --coordinator COORDINATOR or by setting the GALAXY_COORDINATOR environment variable.")
end
return [command, filter, options, is_agent, args.drop(1)]
end
|