bin/flapjack-populator in flapjack-0.7.29 vs bin/flapjack-populator in flapjack-0.7.30
- old
+ new
@@ -17,35 +17,52 @@
require 'flapjack/data/contact'
require 'flapjack/data/entity'
require 'flapjack/data/event'
options = OpenStruct.new
-options.config = Flapjack::Configuration::DEFAULT_CONFIG_PATH
-options.daemonize = nil
+options.config = Flapjack::Configuration::DEFAULT_CONFIG_PATH
-command = ARGV.shift
+exe = File.basename(__FILE__)
-banner = "Usage: flapjack-populator command [options]\n"
-banner += "\n"
-banner += " commands:\n"
-banner += " - import-entities\n"
-banner += " - import-contacts\n"
-banner += " - purge-events (purge queued monitoring events)\n"
+optparse = OptionParser.new do |opts|
+ opts.banner = "Usage: #{exe} COMMAND [OPTIONS]"
-OptionParser.new do |opts|
- opts.banner = "Usage: flapjack-populator command [options]"
+ opts.separator ""
+ opts.separator "Commands:"
+ opts.separator " import-entities"
+ opts.separator " import-contacts"
+ opts.separator " purge-events purge queued monitoring events"
+ opts.separator ""
+ opts.separator "Options"
opts.on("-c", "--config [PATH]", String, "PATH to the config file to use") do |c|
options.config = c
end
opts.on("-f", "--from [FILE]", String, "path to the FILE to import") do |f|
options.from = f
end
-end.parse!(ARGV)
+end
+optparse.parse!(ARGV)
+if options.help
+ puts optparse
+ exit
+elsif options.version
+ puts Flapjack::VERSION
+ exit
+elsif !["import-contacts", "import-entities", "purge-events"].include?(ARGV[0])
+ if ARGV.nil? || ARGV.empty?
+ puts "No command provided"
+ else
+ puts "Unknown command provided: '#{ARGV[0]}'"
+ end
+ puts "\n#{optparse}"
+ exit 1
+end
+
FLAPJACK_ENV = ENV['FLAPJACK_ENV'] || 'production'
config = Flapjack::Configuration.new
config.load(options.config)
config_env = config.all
@@ -59,10 +76,10 @@
if options.from
filename = options.from
file = File.new(filename)
end
-case command
+case ARGV[0]
when "import-contacts"
contacts = Oj.load(file)
if contacts && contacts.is_a?(Enumerable) && contacts.any? {|e| !e['id'].nil?}
@persistence = Redis.new(redis_options)