Parent

Methods

Camping::Server::Options

Constants

DB
HOME
RC

Public Instance Methods

parse!(args) click to toggle source
# File lib/camping/server.rb, line 42
def parse!(args)
  args = args.dup
  options = {}
  
  opt_parser = OptionParser.new("", 24, '  ') do |opts|
    opts.banner = "Usage: camping app1.rb app2.rb..."
    opts.define_head "#{File.basename($0)}, the microframework ON-button for ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
    opts.separator ""
    opts.separator "Specific options:"
    
    opts.on("-h", "--host HOSTNAME",
    "Host for web server to bind to (default is all IPs)") { |v| options[:Host] = v }
    
    opts.on("-p", "--port NUM",
    "Port for web server (defaults to 3301)") { |v| options[:Port] = v }
    
    db = DB.sub(HOME, '~/') if DB
    opts.on("-d", "--database FILE",
    "SQLite3 database path (defaults to #{db ? db : '<none>'})") { |db_path| options[:database] = db_path }
    
    opts.on("-C", "--console",
    "Run in console mode with IRB") { options[:server] = "console" }
    
    server_list = ["thin", "webrick", "console"]
    opts.on("-s", "--server NAME",
    "Server to force (#{server_list.join(', ')})") { |v| options[:server] = v }

    opts.separator ""
    opts.separator "Common options:"
    
    # No argument, shows at tail.  This will print an options summary.
    # Try it and see!
    opts.on_tail("-?", "--help", "Show this message") do
      puts opts
      exit
    end

    # Another typical switch to print the version.
    opts.on_tail("-v", "--version", "Show version") do
      puts Gem.loaded_specs['camping'].version
      exit
    end
  end
  
  opt_parser.parse!(args)
  
  if args.empty?
    puts opt_parser
    exit
  end
  
  options[:script] = args.shift
  options
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.