require 'optparse' module Daemonic module CLI def self.parse(args) options = {} parser = OptionParser.new do |opts| opts.banner = "Usage: #{$0} options" opts.on("--command COMMAND", "The command to start") do |command| options[:command] = command end opts.on("--[no-]daemonize", "Start process in background") do |daemonize| options[:daemonize] = daemonize end opts.on("--workers NUM", Integer, "Amount of workers (default: 1)") do |workers| options[:workers] = workers end opts.on("--pid FILENAME", "Location of pid files") do |pidfile| options[:pidfile] = pidfile end opts.on("--working-dir DIRECTORY", "Specify the working directory") do |dir| options[:working_dir] = dir end opts.on("--name NAME", "Name of the server") do |name| options[:program_name] = name end opts.on("--log FILENAME", "Send daemon_of_the_fall output to a file") do |logfile| options[:logfile] = logfile end opts.on("--loglevel LEVEL", [:debug, :info, :warn, :fatal], "Set the log level (default: info)") do |level| options[:loglevel] = level end opts.on("--config FILENAME", "Read settings from a file") do |config_file| options[:config_file] = config_file end opts.on_tail("--version", "Shows the version") do require "daemonic/version" puts "#{$0}: version #{Daemonic::VERSION}" exit 0 end opts.on_tail("--help", "You're watching it") do puts opts exit 0 end end parser.parse!(args.dup) options end end end