#! /usr/bin/env ruby require 'optparse' command = ARGV[0] commands = %w(on off buff start stop restart console get put post delete patch config migrate migration deploy test init help) if not commands.include? command puts "Enter a command: #{commands.join(", ")}" puts "waxx --help for all options" exit 1 end def parse_options(commands) options = { sub_command: ARGV[1], port: 7700, base: Dir.pwd, env: "active", pid_path: "tmp/pids/waxx.pid", daemonize: false, log_path: "log/waxx.log", user: ENV['USER'], group: nil, debug: false, to: "stage", app: "all", format: "yaml" } headline = ["Waxx", "The high-performance flexible framework"].compact.join(" - ") OptionParser.new do |opts| opts.summary_width = 25 opts.banner = [headline, "\n\n", "Usage: waxx command [-b base_dir] [-p port] [-P pid_file] [-d] [-e env_name] [-l file] [-u user] [-g group] [-f format]\n", "Commands: #{commands.join(" ")}\n", " waxx help:\n"].compact.join("") opts.separator "" opts.on("-p", "--port PORT", Integer, "Specify port", "(default: #{options[:port]})") do |v| options[:port] = v end opts.on("-b", "--base DIR", String, "The base/root directory of the app. Should contain: app, bin, opt, log, etc.", "(default: cwd: #{options[:base]})") do |v| options[:base] = v.sub(/\/$/,"") end opts.on("-e", "--env ENVIRONMENT", String, "The env to find the config.yaml file.", "(default: #{options[:env]})") do |v| options[:env] = v end opts.on("-P", "--pid FILE", String, "save PID in FILE when using -d option.", "(default: #{options[:pid_path]})") do |v| options[:pid_path] = File.expand_path(v) end opts.on("-d", "--daemon", "Daemonize mode", "(default: false)") do |v| options[:daemonize] = v end opts.on("-l", "--log FILE", String, "Logfile for output", "(default: /var/log/#{@name}.log)") do |v| options[:log_path] = v end opts.on("-n", "--name NAME", String, "The name of the migration", "(default: ask)") do |name| options[:name] = name end opts.on("-t", "--to TO", String, "Where to deploy to (defined in opt/deploy.yaml)", "(default: stage)") do |to| options[:to] = to end opts.on("-u", "--user USER", String, "User to run as", "(default: current user)") do |user| options[:user] = user end opts.on("-g", "--group GROUP", String, "Group to run as", "(default: current user's primary group)") do |group| options[:group] = group end opts.on("-D", "--debug", "Output debug messages (console only) 0-9","(default: 0)") do |level| options[:debug] = level end opts.on("-a", "--app app_name or all", "The app to test.","(default: all)") do |app| options[:app] = app end opts.on("-f", "--format FORMAT", String, "The format output that supports it (tests and config) (yaml or json).","(default: yaml)") do |format| options[:format] = format end opts.on_tail("-h", "--help", "Display this usage information.") do puts "#{opts}\n" exit end end.parse! options end opts = parse_options(commands) require_relative '../lib/waxx' $:.unshift "#{opts[:base]}" if %w(init help).include? command Waxx::Conf["opts"] = opts else Waxx::Conf.load_yaml(opts[:base], opts[:env]) Waxx::Conf["opts"] = opts require "#{opts[:base]}/app/app" end if Waxx::Console::Command.respond_to? command if %w(migration).include? command Waxx::Console::Command.send(command, ARGV[1], ARGV[2], opts) elsif %w(get post put delete patch test deploy migration migrate).include? command Waxx::Console::Command.send(command, ARGV[1], opts) else Waxx::Console::Command.send(command, opts) end else puts "The #{command} command has not been implemented yet. opts: #{opts.inspect} conf: #{Waxx::Conf.data.inspect}" end