Sha256: 98b567b971f69f1a7e71f5b48fdb4edf8913dd2ce7373faa4bb7cd6ebdb099c7

Contents?: true

Size: 1.38 KB

Versions: 7

Compression:

Stored size: 1.38 KB

Contents

require_relative 'main/common'

module SubZero
  module Main
    include Common
    extend self

    attr_accessor :config, :cli_args

    def boot cli_args
      log "booting..."

      log "\tloading service.yml"
      @config = load_config
      log "\tparsing CLI args"
      @cli_args = parse_cli_args cli_args

      self
    end

    #######
    private
    #######


    def usage(s)
      $stderr.puts "<%= name %> v#{SubZero::VERSION}" # change to const for the service!
      $stderr.puts s
      $stderr.puts "Usage: #{File.basename($0)}: [-p port] [-l log_path] [-pp pid_path]"
      exit(1)
    end

    def parse_cli_args args
      opts = {}

      port     = @config['service']['broker_port']
      pid_path = log_path = File.join( File.dirname(__FILE__), '..')

      loop { case ARGV[0]
          when '-p' then  ARGV.shift; port = ARGV.shift
          when '-l' then  ARGV.shift; log_path = ARGV.shift
          when '-pp' then ARGV.shift; pid_path = ARGV.shift
          when /^-/ then  usage("Unknown option: #{ARGV[0].inspect}")
          else break
      end; }

      opts[:port]     = port
      opts[:log_path] = log_path
      opts[:pid_path] = pid_path

      opts
    end

    def load_config
      begin
        YAML.load_file('config/service.yml')[env]
      rescue => ex
        log "could not load config file! (#{ex.message})", 'ERROR'
        exit 1
      end
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sub_zero-0.0.9 lib/sub_zero/main.rb
sub_zero-0.0.8 lib/sub_zero/main.rb
sub_zero-0.0.7 lib/sub_zero/main.rb
sub_zero-0.0.6 lib/sub_zero/main.rb
sub_zero-0.0.5 lib/sub_zero/main.rb
sub_zero-0.0.4 lib/sub_zero/main.rb
sub_zero-0.0.3 lib/sub_zero/main.rb