Module: Vayacondios::Server::ApiOptions

Included in:
Api
Defined in:
lib/vayacondios/server/api_options.rb

Instance Method Summary collapse

Instance Method Details

#options_parser(opts, options) ⇒ Object



4
5
6
7
8
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
52
53
54
55
# File 'lib/vayacondios/server/api_options.rb', line 4

def options_parser opts, options
  opts.banner = <<-BANNER.gsub(/^ {8}/, '').strip
    usage: vcd-server [--param=value|--param|-p value|-p]

    Vayacondios server lets any system that can speak JSON over HTTP read
    and write configuration and events.

    It provides the following HTTP endpoints, all of which assume a
    JSON-encoded request body.

    Events:
      GET    /v2/ORG/event/TOPIC/ID
      POST   /v2/ORG/event/TOPIC[/ID]      (announce)
      DELETE /v2/ORG/event/TOPIC/ID
      GET    /v2/ORG/events/TOPIC          (events)
      DELETE /v2/ORG/events/TOPIC

    Stashes:
      GET    /v2/ORG/stash/TOPIC[/ID]      (get)
      POST   /v2/ORG/stash/TOPIC[/ID]      (set!)
      DELETE /v2/ORG/stash/TOPIC[/ID]      (delete)
      GET    /v2/ORG/stashes               (stashes)
      DELETE /v2/ORG/stashes               (delete_many)
  BANNER

  opts.separator ''
  opts.separator 'Database options:'

  options[Goliath.env] ||= {}
  options[Goliath.env][:database] ||= {}
  db_options = options[Goliath.env][:database]

  defaults = DbConfig.defaults[Goliath.env][:database]
  opts.on('-d', '--database.driver NAME', "Database driver (default: #{defaults[:driver]})") do |name|
    db_options[:driver] = name
  end
  opts.on('-h', '--database.host HOST', "Database host (default: #{defaults[:host]})") do |host|
    db_options[:host] = host
  end
  opts.on('-o', '--database.port PORT', Integer, "Database port (default: #{defaults[:port]})") do |port|
    db_options[:port] = port
  end
  opts.on('-D', '--database.name NAME', "Database name (default: #{defaults[:name]})") do |name|
    db_options[:name] = name
  end
  opts.on('-n', '--database.connections NUM', Integer, "Number of database connections to make (default: #{defaults[:connections]}). Production only") do |num|
    db_options[:connections] = num
  end

  options[:config] = File.join(Vayacondios.library_dir, 'config/vcd-server.rb')
  options[:port]   = Vayacondios::DEFAULT_SERVER_PORT
end