Class: WebsolrOptionParser
- Inherits:
-
OptionParser
- Object
- OptionParser
- WebsolrOptionParser
- Defined in:
- lib/websolr_option_parser.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize ⇒ WebsolrOptionParser
constructor
A new instance of WebsolrOptionParser.
- #parse! ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize ⇒ WebsolrOptionParser
Returns a new instance of WebsolrOptionParser.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/websolr_option_parser.rb', line 27 def initialize self. = {} super do |opts| yield opts if block_given? opts. = usage opts.on("-u", "--user=USER", "Your Websolr username") do |u| [:user] = u end opts.on("-p", "--password=PASSWORD", "Your Websolr password") do |p| [:pass] = p end opts.on("-n", "--name=NAME", "Name of the index") do |p| [:name] = p end opts.on("-e", "--rails-env=ENV", "RAILS_ENV") do |p| [:rails_env] = p end opts.on("-i", "--invitation=CODE", "Your invitation code") do |p| [:invitation_code] = p end opts.on_tail("-h", "--help", "Show this message") do puts opts exit end end end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/websolr_option_parser.rb', line 4 def @options end |
Instance Method Details
#parse! ⇒ Object
21 22 23 24 25 |
# File 'lib/websolr_option_parser.rb', line 21 def parse! super self.[:command] = ARGV[0] self.[:name] ||= ARGV[1] end |
#usage ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/websolr_option_parser.rb', line 6 def usage "Usage: #{$0} COMMAND [INDEX_NAME] [options] COMMANDs: local:start - starts the local development server local:stop - stops the local development server add - creates a new index list - shows your indexes delete - deletes an index configure - adds websolr to your current Rails app " end |