Class: PuppetHerald::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-herald/cli.rb

Class Method Summary collapse

Class Method Details

.parse_optionsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/puppet-herald/cli.rb', line 9

def self.parse_options
  usage = ""
  banner = "\#{PuppetHerald::NAME} v\#{PuppetHerald::VERSION} - \#{PuppetHerald::SUMMARY}\n\n\#{PuppetHerald::DESCRIPTION}\n\nUsage: \#{$0} [options]\n\nFor --dbconn option you can use both PostgreSQL and SQLite3 (postgresql://host/db, sqlite://file/path).\nCAUTION! For security reasons, don't pass password in connection string, use --passfile option!\n\n  eos\n  home = File.expand_path('~')\n  defaultdb     = \"sqlite://\#{home}/pherald.db\"\n  defaultdbpass = \"\#{home}/.pherald.pass\"\n  parser = Parser.new do |p|\n    p.banner = banner\n    p.version = PuppetHerald::VERSION\n    p.option :bind, \"Hostname to bind to\", :default => 'localhost'\n    p.option :port, \"Port to use\", :default => 11303, :value_satisfies => lambda {|x| x >= 100 && x <= 65000}\n    p.option :dbconn, \"Connection string to database, see info above\", :default => defaultdb\n    p.option :passfile, \"If using postgresql, this file will be read for password to database\", :default => defaultdbpass\n  end\n  options = parser.process!\n\n  puts \"Starting \#{PuppetHerald::NAME} v\#{PuppetHerald::VERSION}...\"\n  PuppetHerald::Database.dbconn   = options[:dbconn]\n  PuppetHerald::Database.passfile = options[:passfile]\n  begin\n    PuppetHerald::Database.validate! :echo => true\n  rescue Exception => ex\n    STDERR.puts \"FATAL ERROR - Database configuration is invalid!\\n\\n\#{ex.message}\"\n    exit 2\n  end\n  begin\n    PuppetHerald::App.run! options\n  rescue Exception => ex\n    bug = PuppetHerald::App.bug(ex)\n    STDERR.puts \"FATAL ERROR - Unexpected error occured, mayby a bug?\\n\\n\#{bug[:message]}\\n\\n\#{bug[:help]}\"\n    exit 1\n  end\nend\n"