#!/usr/bin/env ruby 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 parser = 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.separator "" opts.separator "Reporting options:" opts.on "--output FILE", "Write report to this file (default: stdout)" do |report_path| options.output = report_path end opts.separator "" opts.separator "Common options:" opts.on "--load_path PATH", "Path to experiments directory (default: #{playground.load_path})" do |load_path| playground.load_path = load_path end opts.on "-d", "--database url", "Database connection URL (e.g. redis://localhost:6379)" do |conn| playground.establish_connection(conn) 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 parser.parse!(ARGV) if ARGV.empty? puts parser.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 else puts "No such command: #{cmd}" end end