class PuppetHerald::CLI
A CLI
class
Public Class Methods
Public Instance Methods
run!(argv = ARGV)
click to toggle source
Protected Instance Methods
parse(argv)
click to toggle source
Parse an ARGV command line arguments @param argv [Array] an argv from CLI
@return [Hash] options to use by application
# File lib/puppet-herald/cli.rb, line 33 def parse(argv) options = parser.process!(argv) msg = "Starting #{PuppetHerald::NAME} v#{PuppetHerald::VERSION} in #{PuppetHerald.rackenv}..." PuppetHerald.logger.info msg PuppetHerald.database.dbconn = options[:dbconn] PuppetHerald.database.passfile = options[:passfile] PuppetHerald.database.spec(true) options end
Private Instance Methods
parse_or_kill(argv, retcode)
click to toggle source
# File lib/puppet-herald/cli.rb, line 55 def parse_or_kill(argv, retcode) return parse argv rescue StandardError => ex PuppetHerald.errlogger.fatal "Database configuration is invalid!\n\n#{ex.message}" Kernel.exit retcode end
parser()
click to toggle source
# File lib/puppet-herald/cli.rb, line 77 def parser home = File.expand_path('~') defaultdb = "sqlite://#{home}/pherald.db" defaultdbpass = "#{home}/.pherald.pass" Parser.new do |p| p.banner = banner p.version = PuppetHerald::VERSION p.option :bind, 'Hostname to bind to', default: 'localhost' p.option :port, 'Port to use', default: 11_303, value_satisfies: ->(x) { x >= 1 && x <= 65_535 } p.option :dbconn, 'Connection string to database, see info above', default: defaultdb p.option( :passfile, 'If using postgresql, this file will be read for password to database', default: defaultdbpass ) end end
run_or_kill(options, retcode)
click to toggle source
# File lib/puppet-herald/cli.rb, line 46 def run_or_kill(options, retcode) require 'puppet-herald/application' PuppetHerald::Application.run! options rescue StandardError => ex bug = PuppetHerald.bug(ex) PuppetHerald.errlogger.fatal "Unexpected error occured, mayby a bug?\n\n#{bug[:message]}\n\n#{bug[:help]}" Kernel.exit retcode end