forked from assaf/vanity
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vanity
executable file
·69 lines (63 loc) · 2.08 KB
/
vanity
1
2
3
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env ruby
# Is there a better way to detect Rails?
if File.exist?("config/boot.rb") && File.exist?("config/environment.rb")
require "config/environment"
else
path = File.expand_path("../lib", File.dirname(__FILE__))
$LOAD_PATH.unshift path unless $LOAD_PATH.include?(path)
require "vanity"
end
require "optparse"
playground = Vanity.playground
options = Struct.new(:output).new
opts = OptionParser.new("", 24, " ") do |opts|
opts.banner = "Usage: #{File.basename($0)} [options] command\n"
opts.banner << "Commands:\n"
opts.banner << " list List all experiments and metrics\n"
opts.banner << " report Report on all running experiments/metrics\n"
opts.banner << " upgrade Upgrade your database when deploying new release\n"
opts.separator ""
opts.separator "Reporting options:"
opts.on "--output FILE", "Write report to this file (default: stdout)" do |path|
options.output = path
end
opts.separator ""
opts.separator "Common options:"
opts.on "--load_path PATH", "Path to experiments directory (default: #{playground.load_path})" do |path|
playground.load_path = path
end
opts.on "-d", "--database url", "Database connection URL (e.g. redis:/localhost:6379)" do |conn|
playground.establish_connection conn
end
opts.on "--redis HOST:PORT:DB", "DEPRECATED: Redis server host (default: localhost:6379)" do |redis|
host, port, db = redis.split(":")
playground.establish_connection "redis:/#{host}:#{port}/#{db}"
end
opts.on_tail "-h", "--help", "Show this message" do
puts opts.to_s.gsub(/^.*DEPRECATED.*$/s, '')
exit
end
opts.on_tail "-v", "--version", "Show version" do
puts "Vanity #{Vanity::Version::STRING}"
exit
end
end
opts.parse!(ARGV)
if ARGV.empty?
puts opts.banner
exit
end
ARGV.each do |cmd|
case cmd
when "report"
require "vanity/commands/report"
Vanity::Commands.report options.output
when "list"
require "vanity/commands/list"
Vanity::Commands.list
when "upgrade"
require "vanity/commands/upgrade"
Vanity::Commands.upgrade
else fail "No such command: #{cmd}"
end
end