Sha256: e34ba44efb56ab1615fba6ce3e702b75ead9ea82212ed765653892f4c7b9cc56

Contents?: true

Size: 1.15 KB

Versions: 22

Compression:

Stored size: 1.15 KB

Contents

require 'optparse'

class Common
  def initialize
    @options = {}
  end

  def parse
    options = {}

    OptionParser.new do |opt|
      opt.on("--hostname HOSTNAME", String,  "Hostname") { |v| options[:hostname]  = v }
      opt.on("--port PORT",         Integer, "Port"    ) { |v| options[:port]      = v }
      opt.on("--username USERNAME", String,  "Username") { |v| options[:user]      = v }
      opt.on("--password PASSWORD", String,  "Password") { |v| options[:password]  = v }
      opt.on("--debug") { ManageIQ::Messaging.logger = Logger.new(STDOUT) }
      opt.parse!
    end

    options[:hostname]   ||= ENV["QUEUE_HOSTNAME"] || "localhost"
    options[:port]       ||= ENV["QUEUE_PORT"]     || 61616
    options[:user]       ||= ENV["QUEUE_USER"]     || "admin"
    options[:password]   ||= ENV["QUEUE_PASSWORD"] || "smartvm"

    options[:port] = options[:port].to_i

    @options = options
    self
  end

  def q_options
    {
      :host       => @options[:hostname],
      :port       => @options[:port].to_i,
      :username   => @options[:user],
      :password   => @options[:password],
      :client_ref => "background_example",
    }
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
manageiq-messaging-1.5.0 examples/common.rb
manageiq-messaging-1.4.3 examples/common.rb
manageiq-messaging-1.4.2 examples/common.rb
manageiq-messaging-1.4.1 examples/common.rb
manageiq-messaging-1.4.0 examples/common.rb
manageiq-messaging-1.3.0 examples/common.rb
manageiq-messaging-1.2.0 examples/common.rb
manageiq-messaging-1.1.2 examples/common.rb
manageiq-messaging-1.1.1 examples/common.rb
manageiq-messaging-1.1.0 examples/common.rb
manageiq-messaging-0.1.7 examples/common.rb
manageiq-messaging-1.0.3 examples/common.rb
manageiq-messaging-1.0.2 examples/common.rb
manageiq-messaging-1.0.1 examples/common.rb
manageiq-messaging-1.0.0 examples/common.rb
manageiq-messaging-0.1.6 examples/common.rb
manageiq-messaging-0.1.5 examples/common.rb
manageiq-messaging-0.1.4 examples/common.rb
manageiq-messaging-0.1.3 examples/common.rb
manageiq-messaging-0.1.2 examples/common.rb