Sha256: 46b469d76b854a1fde8c9c07f7c509aaa3d1e1e2588590fb14fe4895e04c0145

Contents?: true

Size: 1.05 KB

Versions: 12

Compression:

Stored size: 1.05 KB

Contents

require "optparse"

module Agig::OptParser
  def self.parse!(argv)
    opts = {
      :port  => 16705,
      :host  => "localhost",
      :log   => nil,
      :debug => false,
      :foreground => false,
    }

    OptionParser.new do |parser|
      parser.instance_eval do
        self.banner  = "Usage: #{$0} [opts]"
        separator ""

        separator "Options:"
        on("-p", "--port [PORT=#{opts[:port]}]", "port number to listen") do |port|
          opts[:port] = port
        end

        on("-h", "--host [HOST=#{opts[:host]}]", "host name or IP address to listen") do |host|
          opts[:host] = host
        end

        on("-l", "--log LOG", "log file") do |log|
          opts[:log] = log
        end

        on("-d", "--debug", "Enable debug mode") do |debug|
          opts[:log]   = $stdout
          opts[:debug] = true
        end

        on("-f", "--foreground", "run foreground") do |foreground|
          opts[:log]        = $stdout
          opts[:foreground] = true
        end

        parse!(argv)
      end
    end

    opts
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
agig-0.1.5 lib/agig/optparse.rb
agig-0.1.4 lib/agig/optparse.rb
agig-0.1.3 lib/agig/optparse.rb
agig-0.1.2 lib/agig/optparse.rb
agig-0.1.1 lib/agig/optparse.rb
agig-0.1.0 lib/agig/optparse.rb
agig-0.0.6 lib/agig/optparse.rb
agig-0.0.5 lib/agig/optparse.rb
agig-0.0.4 lib/agig/optparse.rb
agig-0.0.3 lib/agig/optparse.rb
agig-0.0.2 lib/agig/optparse.rb
agig-0.0.1 lib/agig/optparse.rb