Created
November 27, 2011 03:29
-
-
Save bil-bas/1396889 to your computer and use it in GitHub Desktop.
Z&G: maybe not suppress the errors?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'optparse' | |
EXTRACT_PATH = File.dirname(File.dirname(File.expand_path(__FILE__))) | |
ROOT_PATH = if ENV['OCRA_EXECUTABLE'] | |
File.dirname(File.expand_path(ENV['OCRA_EXECUTABLE'])) | |
elsif defined? OSX_EXECUTABLE_FOLDER | |
File.dirname(OSX_EXECUTABLE_FOLDER) | |
else | |
EXTRACT_PATH | |
end | |
APP_NAME = File.basename(__FILE__).chomp(File.extname(__FILE__)) | |
RUNNING_FROM_EXECUTABLE = (ENV['OCRA_EXECUTABLE'] or defined?(OSX_EXECUTABLE)) | |
DEFAULT_LOG_FILE = "#{APP_NAME}.log" | |
DEFAULT_LOG_FILE_PATH = File.join(ROOT_PATH, DEFAULT_LOG_FILE) | |
def parse_options | |
options = {} | |
OptionParser.new do |parser| | |
parser.banner =<<TEXT | |
Usage: #{File.basename(__FILE__)} [options] | |
Defaults to using --#{RUNNING_FROM_EXECUTABLE ? 'log' : 'console'} | |
TEXT | |
parser.on('-?', '-h', '--help', 'Display this screen') do | |
puts parser | |
exit | |
end | |
options[:dev] = false | |
parser.on('--dev', 'Development mode') do | |
options[:dev] = true | |
end | |
parser.on('--console', 'Console mode (no log file)') do | |
options[:log] = nil # Write to console. | |
end | |
parser.on('--log [FILE]', "Write log to a file (defaults to '#{DEFAULT_LOG_FILE}')") do |file| | |
options[:log] = file ? file : DEFAULT_LOG_FILE_PATH | |
end | |
parser.on('--timestamp', "Adds a timestamp to the log file") do | |
options[:timestamp] = true | |
end | |
begin | |
parser.parse! | |
rescue OptionParser::ParseError => ex | |
puts "ERROR: #{ex.message}" | |
puts | |
puts parser | |
exit | |
end | |
end | |
options | |
end | |
options = parse_options | |
# Default to console mode normally; default to logfile when running executable. | |
if RUNNING_FROM_EXECUTABLE and not options.has_key?(:log) | |
options[:log] = DEFAULT_LOG_FILE_PATH | |
end | |
LOG_FILE = options[:log] | |
DEVELOPMENT_MODE = options[:dev] | |
ENV['PATH'] = File.join(EXTRACT_PATH, 'bin') + File::PATH_SEPARATOR + ENV['PATH'] | |
require_relative "../lib/main" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment