Sha256: 3d729f564b12c17ba8ebe8ce47274d29db0bdd7279440268c4e86d0ae908efbd

Contents?: true

Size: 1.16 KB

Versions: 6

Compression:

Stored size: 1.16 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 Exception => 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 '/tmp', "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.10 lib/ring/sqa/cli.rb
ring-sqa-0.1.9 lib/ring/sqa/cli.rb
ring-sqa-0.1.8 lib/ring/sqa/cli.rb
ring-sqa-0.1.7 lib/ring/sqa/cli.rb
ring-sqa-0.1.6 lib/ring/sqa/cli.rb
ring-sqa-0.1.5 lib/ring/sqa/cli.rb