Sha256: c593fa523216d985ccc050eb0bc08edf322326408f19af828f65bd59a56db36d

Contents?: true

Size: 1.37 KB

Versions: 15

Compression:

Stored size: 1.37 KB

Contents

module Toiler
  module Utils
    # Parses command-line arguments
    module ArgumentParser
      module_function

      def parse(argv)
        opts = { queues: [] }

        parser = OptionParser.new do |o|
          o.on '-d', '--daemon', 'Daemonize process' do |arg|
            opts[:daemon] = arg
          end

          o.on '-q', '--queue QUEUE1,QUEUE2,...', 'Queues to process' do |arg|
            opts[:active_queues] = arg.split(',')
          end

          o.on '-r', '--require [PATH|DIR]', 'Location of the worker' do |arg|
            opts[:require] = arg
          end

          o.on '-C', '--config PATH', 'Path to YAML config file' do |arg|
            opts[:config_file] = arg
          end

          o.on '-R', '--rails', 'Load Rails' do |arg|
            opts[:rails] = arg
          end

          o.on '-L', '--logfile PATH', 'Path to writable logfile' do |arg|
            opts[:logfile] = arg
          end

          o.on '-P', '--pidfile PATH', 'Path to pidfile' do |arg|
            opts[:pidfile] = arg
          end

          o.on '-v', '--verbose', 'Print more verbose output' do |arg|
            opts[:verbose] = arg
          end
        end

        parser.banner = 'toiler [options]'
        parser.on_tail '-h', '--help', 'Show help' do
          puts parser
          exit 1
        end
        parser.parse!(argv)
        opts
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
toiler-0.6.1 lib/toiler/utils/argument_parser.rb
toiler-0.6.0 lib/toiler/utils/argument_parser.rb
toiler-0.6.0.pre1 lib/toiler/utils/argument_parser.rb
toiler-0.5.1 lib/toiler/utils/argument_parser.rb
toiler-0.5.1.pre9 lib/toiler/utils/argument_parser.rb
toiler-0.5.1.pre7 lib/toiler/utils/argument_parser.rb
toiler-0.5.1.pre6 lib/toiler/utils/argument_parser.rb
toiler-0.5.1.pre5 lib/toiler/utils/argument_parser.rb
toiler-0.5.1.pre4 lib/toiler/utils/argument_parser.rb
toiler-0.5.1.pre3 lib/toiler/utils/argument_parser.rb
toiler-0.5.1.pre2 lib/toiler/utils/argument_parser.rb
toiler-0.5.1.pre1 lib/toiler/utils/argument_parser.rb
toiler-0.5.0 lib/toiler/utils/argument_parser.rb
toiler-0.4.3 lib/toiler/utils/argument_parser.rb
toiler-0.4.2 lib/toiler/utils/argument_parser.rb