Sha256: 81c31d59ef91189cab107f18b8bf39a5320d3522f59d1c31c187ece7ea4490a5

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
daemonic-0.0.2 lib/daemonic/cli.rb
daemonic-0.0.1 lib/daemonic/cli.rb