Class: Quebert::CommandLineRunner
- Inherits:
-
Object
- Object
- Quebert::CommandLineRunner
- Defined in:
- lib/quebert/command_line_runner.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#command ⇒ Object
Returns the value of attribute command.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(argv) ⇒ CommandLineRunner
constructor
A new instance of CommandLineRunner.
-
#parse! ⇒ Object
Parse the options.
- #parser ⇒ Object
Constructor Details
#initialize(argv) ⇒ CommandLineRunner
Returns a new instance of CommandLineRunner.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/quebert/command_line_runner.rb', line 6 def initialize(argv) @argv = argv # Default options values @options = { :chdir => Dir.pwd } parse! end |
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
4 5 6 |
# File 'lib/quebert/command_line_runner.rb', line 4 def arguments @arguments end |
#command ⇒ Object
Returns the value of attribute command.
4 5 6 |
# File 'lib/quebert/command_line_runner.rb', line 4 def command @command end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/quebert/command_line_runner.rb', line 4 def @options end |
Class Method Details
.dispatch(args = ARGV) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/quebert/command_line_runner.rb', line 39 def self.dispatch(args = ARGV) runner = new(args) params = runner. if dir = params[:chdir] Dir.chdir dir end if pid_file = params[:pid] Support::PidFile.new(pid_file).write! end if log_path = params[:log] Quebert.config.log_file_path = log_path end if config = params[:config] || auto_config require config end Worker.new.start end |
Instance Method Details
#parse! ⇒ Object
Parse the options.
33 34 35 36 37 |
# File 'lib/quebert/command_line_runner.rb', line 33 def parse! parser.parse! @argv @command = @argv.shift @arguments = @argv end |
#parser ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/quebert/command_line_runner.rb', line 17 def parser @parser ||= OptionParser.new do |opts| opts. = "Usage: quebert [options]" opts.separator "" opts.on("-l", "--log FILE", "File to redirect output " + "(default: #{@options[:log]})") { |file| @options[:log] = file } opts.on("-P", "--pid FILE", "File to store PID " + "(default: #{@options[:pid]})") { |file| @options[:pid] = file } opts.on("-C", "--config FILE", "Load options from config file") { |file| @options[:config] = file } opts.on("-c", "--chdir DIR", "Change to dir before starting") { |dir| @options[:chdir] = File.(dir) } end end |