Adding --version and fixing the config and command line options

This commit is contained in:
Chris Cowan 2014-08-28 09:41:11 -07:00
parent 440ba941d7
commit c678bbc7f1
3 changed files with 59 additions and 28 deletions

View file

@ -1,36 +1,68 @@
#!/usr/bin/env ruby
#
# This file was generated by RubyGems.
#
# The application 'puma' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require "optparse"
require "pp"
require 'rubygems'
version = ">= 0"
require 'puma/cli'
require "yaml"
HERE = File.expand_path(File.dirname(__FILE__))
if ARGV.first
str = ARGV.first
str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
if str =~ /\A_(.*)_\z/
version = $1
ARGV.shift
# Defaults for the options
options = {
:config => File.expand_path("#{HERE}/../config/kibana.yml") || ENV["CONFIG_PATH"]
}
# Create a new parser
parser = OptionParser.new do |opts|
opts.on('-e', '--elasticsearch URI', 'Elasticsearch instance') do |arg|
options[:elasticsearch] = arg
end
opts.on('-c', '--config PATH', 'Path to config file') do |arg|
options[:config] = arg
end
opts.on('-p', '--port PORT', 'Kibana port') do |arg|
options[:port] = arg
end
opts.on('-v', '--version', 'Display version') do |arg|
puts ENV['KIBANA_VERSION'] || 'dev-build'
exit
end
opts.on('-h', '--help', 'Display this screen') do
puts opts
exit
end
end
# Include the puma config unless it's been overriden
unless ARGV.include?('--port') or ARGV.include?('-p')
ARGV << '--port'
ARGV << '5601'
end
# Set the usage banner
parser.banner = "Usage: kibana <options>\n\n"
# Include the rack config if it hasn't been included
if (ARGV.grep(/config\/web\.ru/)).empty?
ARGV << "#{HERE}/../config/web.ru"
end
# Parse the command line arguments
parser.parse! ARGV
gem 'puma', version
load Gem.bin_path('puma', 'puma', version)
# Load the config from default
config = YAML.load(IO.read(options[:config]))
# Set the override for the port
port = (options[:port] || config['port'])
# Set the override for Elasticsaerch
elasticsearch = (options[:elasticsearch] || config['elasticsearch'])
# Set the enviroment vars
ENV["KIBANA_PORT"] = port.to_s
ENV["KIBANA_CONFIG_FILE"] = options[:config]
ENV["KIBANA_ELASTICSEARCH"] = elasticsearch
# Clone argv and then clear it and set up the defaults for the Puma CLI
puma_args = ARGV.clone()
puma_args.clear
puma_args << '--port'
puma_args << port.to_s
puma_args << "#{HERE}/../config/web.ru"
# gem 'puma', version
# load Gem.bin_path('puma', 'puma', version)
#
cli = Puma::CLI.new puma_args
cli.run

View file

@ -1,7 +1,7 @@
@echo off
SETLOCAL
if NOT DEFINED JAVA_HOME goto java_home_err
if not defined JAVA_HOME goto java_home_err
set SCRIPT_DIR=%~dp0
for %%I in ("%SCRIPT_DIR%..") do set DIR=%%~dpfI

View file

@ -9,7 +9,6 @@ if ENV['RACK_ENV'] == ('development')
end
if ENV['RACK_ENV'] == ('production')
ROOT = File.expand_path("#{File.dirname(__FILE__)}/../")
PUBLIC_ROOT = File.expand_path("#{File.dirname(__FILE__)}/../public/")
CONFIG_PATH = ENV["CONFIG_PATH"]
end