Class: FluQ::CLI
- Inherits:
-
Object
- Object
- FluQ::CLI
- Defined in:
- lib/fluq/cli.rb
Constant Summary collapse
- SIGNALS =
[ :QUIT, :INT, :TERM, :HUP ]
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
attr_reader [Hash] options.
Class Method Summary collapse
-
.run ⇒ Object
Runs the CLI.
Instance Method Summary collapse
-
#configured? ⇒ Boolean
True if configured.
-
#initialize ⇒ CLI
constructor
Constructor.
- #run ⇒ Object
Constructor Details
#initialize ⇒ CLI
Constructor
21 22 23 24 25 26 27 |
# File 'lib/fluq/cli.rb', line 21 def initialize super # Parse options @options = {} parser.parse!(ARGV) end |
Instance Attribute Details
#options ⇒ Object (readonly)
attr_reader [Hash] options
10 11 12 |
# File 'lib/fluq/cli.rb', line 10 def @options end |
Class Method Details
.run ⇒ Object
Runs the CLI
13 14 15 16 17 18 |
# File 'lib/fluq/cli.rb', line 13 def self.run if BasicSocket.respond_to?(:do_not_reverse_lookup=) BasicSocket.do_not_reverse_lookup = true end new.run end |
Instance Method Details
#configured? ⇒ Boolean
Returns true if configured.
69 70 71 |
# File 'lib/fluq/cli.rb', line 69 def configured? [:config] && File.file?([:config]) end |
#run ⇒ Object
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 |
# File 'lib/fluq/cli.rb', line 29 def run # Exit if not configured correctly unless configured? puts parser exit end # Boot and add project's lib/ dir to load path require 'fluq' $LOAD_PATH.unshift FluQ.root.join('lib') procline "(starting)" # Setup logger if [:log] FileUtils.mkdir_p(File.dirname([:log])) FluQ.logger = ::Logger.new([:log]) end if [:verbose] FluQ.logger.level = ::Logger::DEBUG end # Write PID file @pidfile = [:pidfile] || FluQ.root.join("tmp", "pids", "fluq.pid") FileUtils.mkdir_p(File.dirname(@pidfile)) File.open(@pidfile, "w") {|f| f.write Process.pid } # Trap signals SIGNALS.each do |signal| trap(signal) {|*| shutdown! } end # Start log "Starting FluQ #{FluQ::VERSION} (#{[:config]})" FluQ::Runner.run do |runner| FluQ::DSL::Root.new([:config]).apply(runner) procline end end |