Class: PostBin::Server

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/postbin/server.rb

Class Method Summary collapse

Class Method Details

.parse_args(argv) ⇒ Object

Parse command line args.



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/postbin/server.rb', line 65

def self.parse_args(argv)
  # default options.
  options = { :bind => '127.0.0.1', :port => 6969, :server => 'thin', :enviroment => :production }

  # available options.
  opts = OptionParser.new('', 24, '  ') do |opts|
    opts.banner = 'Usage: postbin [options]'
    opts.separator ''
    opts.separator 'PostBin options:'
    opts.on('-v', '--version', 'show version number') { $stderr.puts 'PostBin ' + PostBin::Version; exit }
    opts.on('-h', '--help', 'show this message') { $stderr.puts opts; exit; }
    opts.separator ''
    opts.separator 'Rack options:'
    opts.on('-s', '--server SERVER', 'server (webrick, mongrel, thin, etc.)') { |s| options[:server] = s }
    opts.on('-a', '--address HOST', 'listen on HOST address (default: 127.0.0.1)') { |host| options[:bind] = host }
    opts.on('-p', '--port PORT', 'use PORT number (default: 6969)') { |port| options[:port] = port }
  end.parse!(argv)

  options
end

.run_command_line!(argv) ⇒ Object

Runs a server on local machine, called by command line executable.



58
59
60
61
62
# File 'lib/postbin/server.rb', line 58

def self.run_command_line!(argv)
  options = parse_args(argv)
  $stderr.puts "== Starting PostBin on http://#{options[:bind]}:#{options[:port]}"
  run!(options)
end