Skip to content
This repository

Method for OptionParser makes it easier for applications to reuse. #402

Closed
wants to merge 1 commit into from

2 participants

7rans James Tucker
7rans
trans commented

I separated the option parser into a cached method, so that it can be reused by other applications. I presently find myself in this situation where I am creating a CLI front-end for starting up a rack server, but need to support a couple of additional options. Rather then having to duplicate all these options in my own OptionParser it would be convenient to just augment Racks built-in one.

James Tucker
Owner

Test please

James Tucker raggi closed this
7rans

This is a tiny refactor. There is nothing new to test. It should already be tested by current tests. If it's not already tested, then there were never any tests to begin with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jul 06, 2012
7rans trans Separate method for OptionParser makes it easier for applications to …
…reuse.
af6b4fe
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 7 additions and 4 deletions. Show diff stats Hide diff stats

  1. +7 4 lib/rack/server.rb
11 lib/rack/server.rb
@@ -3,9 +3,8 @@
3 3 module Rack
4 4 class Server
5 5 class Options
6   - def parse!(args)
7   - options = {}
8   - opt_parser = OptionParser.new("", 24, ' ') do |opts|
  6 + def opt_parser(options={})
  7 + @opt_parser ||= OptionParser.new("", 24, ' ') do |opts|
9 8 opts.banner = "Usage: rackup [ruby options] [rack options] [rackup config]"
10 9
11 10 opts.separator ""
@@ -81,9 +80,13 @@ def parse!(args)
81 80 exit
82 81 end
83 82 end
  83 + end
  84 +
  85 + def parse!(args)
  86 + options = {}
84 87
85 88 begin
86   - opt_parser.parse! args
  89 + opt_parser(options).parse! args
87 90 rescue OptionParser::InvalidOption => e
88 91 warn e.message
89 92 abort opt_parser.to_s

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.