Sha256: 2ba1b86f7a284af0444b5dfd5568ceec51ddd019eca66d827dc3fb101a42939c

Contents?: true

Size: 1.93 KB

Versions: 6

Compression:

Stored size: 1.93 KB

Contents

#!/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'
  Adminix::Config.instance.secret_key = options[:secret_key]
  Adminix::Config.instance.service_id = options[:service_id]
  Adminix::Config.instance.daemon = options[:daemonize]
end

case options[:action]
  when "env" 
    puts Adminix::Service.instance.options_to_envs
  when "watch"
    puts Adminix::Watcher.run!(options)
  when "version"
    puts "adminix version #{Adminix::VERSION}"
  else
    puts parsers.map { |v| v[1].to_s }
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
adminix-0.1.20 exe/adminix
adminix-0.1.19 exe/adminix
adminix-0.1.18 exe/adminix
adminix-0.1.17 exe/adminix
adminix-0.1.16 exe/adminix
adminix-0.1.15 exe/adminix