Class: WebsolrOptionParser

Inherits:
OptionParser
  • Object
show all
Defined in:
lib/websolr_option_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWebsolrOptionParser

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.options = {}
  super do |opts|
    
    yield opts if block_given?

    opts.banner = usage

    opts.on("-u", "--user=USER", "Your Websolr username") do |u|
      options[:user] = u
    end

    opts.on("-p", "--password=PASSWORD", "Your Websolr password") do |p|
      options[:pass] = p
    end
    
    opts.on("-n", "--name=NAME", "Name of the index") do |p|
      options[:name] = p
    end
    
    opts.on("-e", "--rails-env=ENV", "RAILS_ENV") do |p|
      options[:rails_env] = p
    end
    
    opts.on("-i", "--invitation=CODE", "Your invitation code") do |p|
      options[:invitation_code] = p
    end

    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end
  end
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



4
5
6
# File 'lib/websolr_option_parser.rb', line 4

def options
  @options
end

Instance Method Details

#parse!Object



21
22
23
24
25
# File 'lib/websolr_option_parser.rb', line 21

def parse!
  super
  self.options[:command] = ARGV[0]
  self.options[:name] ||= ARGV[1]
end

#usageObject



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