Module: Ayl::CommandLine

Defined in:
lib/ayl-beanstalk/command_line.rb

Constant Summary collapse

BEANSTALK_TUBE_DEFAULT =
'default'
APP_REQUIRE_DEFAULT =
'config/environment'
RAILS_ENVIRONMENT_DEFAULT =
'production'
MARKER =
'--'

Class Method Summary collapse

Class Method Details

.grab_app_arguments(argv = ARGV) ⇒ Object



13
14
15
16
17
# File 'lib/ayl-beanstalk/command_line.rb', line 13

def self.grab_app_arguments(argv=ARGV)
  marker_index = argv.index(MARKER)
  raise "No argument marker found!" if marker_index.nil?
  argv[marker_index + 1..-1]
end

.parse!(argv = ARGV) ⇒ Object



19
20
21
22
23
24
25
26
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
61
62
63
64
65
66
67
68
69
# File 'lib/ayl-beanstalk/command_line.rb', line 19

def self.parse!(argv=ARGV)
  {}.tap do | options |

    optparse = OptionParser.new do | opts |
      
      # Set a banner, displayed at the top of the help screen.
      opts.banner = "Usage: #{$0} [options]"

      options[:tube] = BEANSTALK_TUBE_DEFAULT
      opts.on '-t', '--tube TUBE', "Specify the beanstalk tube to listen to. Default (#{BEANSTALK_TUBE_DEFAULT})." do |tube|
        options[:tube] = tube
      end

      options[:env] = RAILS_ENVIRONMENT_DEFAULT
      opts.on '-e', '--environment ENVIRONMENT', "Specify the Rails environment to use" do |environment|
        options[:env] = environment
      end

      options[:app_path] = nil
      opts.on '-a', '--app-path APP_PATH', "Specify the path to the rails app" do |app_path|
        options[:app_path] = app_path
      end

      options[:rails_app] = false
      opts.on '-r', '--rails', "Indicate that we are starting a rails application" do 
        options[:rails_app] = true
      end

      options[:app_require] = APP_REQUIRE_DEFAULT
      opts.on '-c', '--require APP_REQUIRE', "The file to require when the worker starts up" do | app_require |
        options[:app_require] = app_require
      end

      opts.on '-p', '--pid-path PID_PATH', "The path to the pid file" do | pid_path |
        options[:pid_path] = pid_path
      end

      opts.on '-n', '--name NAME', 'The name to use for the worker daemon (overrides script name)' do | name |
        options[:app_name] = name
      end

      opts.on '-h', '--help', 'Display the help message' do
        puts opts
        exit(0)
      end
    end

    optparse.parse!(argv)
  end # End of .tap

end