class HareDo::Admin::Config::Interface
The class implements to command line interface for configuration module
Public Class Methods
new()
click to toggle source
Calls superclass method
HareDo::Admin::Interface::new
# File src/lib/haredo/admin/config.rb, line 10 def initialize() super('config', 'Modify configuration') @commands = {} # Configure/test database connection settings @commands['db'] = lambda do | name | # Write changes to configuration file if @write == true loadConfig() settings = {} password = ENV['PGPASSWORD'] settings['host'] = @host if @host settings['user'] = @username if @username settings['password'] = password if password settings['port'] = @port if @port settings['name'] = @vhost if @vhost settings['ssl'] = true if @ssl @config['system']['db'] = settings saveConfig() end end # Configure/test RabbitMQ connection settings @commands['broker'] = lambda do | name | if @test == true connected = false params = { :user => @username, :password => ENV['RBQPASSWORD'], :port => @port, :vhost => @vhost, :host => @host, :ssl => @ssl } puts params client = HareDo::Peer.new() begin connected = client.connect(params) rescue exit 1 end if connected == true puts 'succeeded' client.disconnect() exit 0 end puts 'failed' exit 1 end if @write == true # Write changes to configuration file loadConfig() settings = {} password = ENV['RBQPASSWORD'] settings['host'] = @host if @host settings['user'] = @username if @username settings['password'] = password if password settings['port'] = @port if @port settings['vhost'] = @vhost if @vhost settings['ssl'] = true if @ssl @config['system']['broker'] = settings saveConfig() end end end
Public Instance Methods
help(opts)
click to toggle source
# File src/lib/haredo/admin/config.rb, line 96 def help(opts) puts opts end
parse(args)
click to toggle source
# File src/lib/haredo/admin/config.rb, line 100 def parse(args) $dir = nil $count = 1 @ssl = false opts = OptionParser.new do |opts| opts.separator '' opts.banner = "Test/update configuration and connection settings\n\n" opts.banner += "Usage: config [options] {db | broker}" opts.separator 'Available options:' opts.on('-c', '--config [val]', String, 'Use specific config file (default /etc/haredo/system.yml)') do |file| @configfile = file $count += 1 end opts.on_tail("-t", "--test", "Test connection settings") do @test = true end opts.on_tail("-h", "--help", "Display help") do puts opts exit end opts.on_tail("-u", "--user [val]", String, "Username to use for connection") do |user| @username = user $count += 1 end opts.on_tail("-s", "--server-host [val]", String, "Host") do |host| @host = host $count += 1 end opts.on_tail("-e", "--encryption [val]", String, "Host to use for connection") do |ssl| if ssl == 'true' @ssl = true end $count += 1 end opts.on_tail("-n", "--name [val]", String, "Name (Database name of RabbitMQ VHost)") do |name| @vhost = name $count += 1 end opts.on_tail("-p", "--port [val]", String, "Port to use for connection)") do |port| @port = port $count += 1 end opts.on_tail("-w", "--write-changed", "Write account setting to configuration file") do @write = true end end opts.parse!(args[0..-1]) command = args[0].chomp if not @commands.has_key?(command) help opts return end @commands[command].call(command) end