#!/usr/bin/env ruby # encoding: utf-8 require 'optparse' options = { action: "help", secret_key: ENV['ADMINIX_SECRET_KEY'], service_id: ENV['ADMINIX_SERVICE_ID'], daemonize: false, stop_daemon: false } parsers = {} parsers[:env] = OptionParser.new do |opts| opts.banner = "Display the commands to define ENV variables" opts.separator " Usage: adminix env [options]" opts.on("--secret-key SECRET_KEY", "define api SECRET_KEY") { |key| options[:secret_key] = key } opts.on("--service-id SERVICE_ID", "define api SERVICE_ID") { |id| options[:service_id] = id } opts.separator "" end parsers[:watch] = OptionParser.new do |opts| opts.banner = "Launch Adminix watcher" opts.separator " Usage: adminix watch" opts.separator " Usage: adminix watch [options]" opts.separator " Options:" opts.on("--secret-key SECRET_KEY", "define api SECRET_KEY") { |key| options[:secret_key] = key } opts.on("--service-id SERVICE_ID", "define api SERVICE_ID") { |id| options[:service_id] = id } opts.on("-d", "--daemonize", "run watcher in background process") { options[:daemonize] = true } opts.on("-s", "--stop-daemon", "stop daemon watcher") { options[:stop_daemon] = true } opts.separator "" end parsers[:version] = OptionParser.new do |opts| opts.banner = "Show the Adminix version" opts.separator " Usage: adminix version" opts.separator "" end options[:action] = ARGV[0] || "help" parsers[options[:action].to_sym].parse!(ARGV) rescue nil unless options[:action] == "help" require 'adminix' config = Adminix::Config.instance config.secret_key = options[:secret_key] config.service_id = options[:service_id] config.daemon = options[:daemonize] config.read_local_config config.sync_remote_config end case options[:action] when "env" puts Adminix::Service.instance.options_to_envs when "watch" if config.credentials_defined? puts Adminix::Watcher.run!(options) else puts 'Credentials are not defined, running setup server' require 'adminix/server_setup' end when "version" puts "adminix version #{Adminix::VERSION}" else puts parsers.map { |v| v[1].to_s } end