Sha256: c8cd61f9b01daf1d943dd8416e79da21e6aa5f92c54a467789486d44d2e3d653

Contents?: true

Size: 1.15 KB

Versions: 6

Compression:

Stored size: 1.15 KB

Contents

require 'slop'
require 'ring/sqa'

module Ring
class SQA

  class CLI
    attr_reader :opts

    def run
      pid = $$
      puts "Running as pid: #{pid}"
      Process.daemon if @opts.daemonize?
      SQA.new
    rescue => error
      crash error
      raise
    end

    private

    def initialize
      _args, @opts = opts_parse
      CFG.debug = @opts.debug?
      CFG.afi = @opts.ipv6? ? "ipv6" : "ipv4"
      CFG.fake  = @opts.fake?
      require_relative 'log'
      Log.level = Logger::DEBUG if @opts.debug?
      run
    end

    def opts_parse
      slop = Slop.new(:help=>true) do
        banner 'Usage: ring-sqad [options]'
        on 'd', '--debug', 'turn on debugging'
        on '6', '--ipv6',  'use ipv6 instead of ipv4'
        on '--fake',       'initialize analyzebuffer with 0 nodes'
        on '--daemonize',  'run in background'
      end
      [slop.parse!, slop]
    end

    def crash error
      file = File.join CFG.directory, 'crash.txt'
      open file, 'w' do |file|
        file.puts error.class.to_s + ' => ' + error.message
        file.puts '-' * 70
        file.puts error.backtrace
        file.puts '-' * 70
      end
    end

  end

end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ring-sqa-0.1.2 lib/ring/sqa/cli.rb
ring-sqa-0.1.1 lib/ring/sqa/cli.rb
ring-sqa-0.1.0 lib/ring/sqa/cli.rb
ring-sqa-0.0.23 lib/ring/sqa/cli.rb
ring-sqa-0.0.22 lib/ring/sqa/cli.rb
ring-sqa-0.0.21 lib/ring/sqa/cli.rb