Sha256: 212cd6b551798aa0d97467691c09241f9bf669a1d84a5eb19b48986f87aabf11

Contents?: true

Size: 1.58 KB

Versions: 2

Compression:

Stored size: 1.58 KB

Contents

require 'configliere'

module Xway
  class Parameter
    def reload!
      @param = Configliere::Param.new
      @param.define :servers,       type: Array,
                                    flag: 's',
                                    description: 'all appway servers',
                                    default: ['http://localhost:8000']
      @param.define 'app.name',     flag: 'a',
                                    description: 'name of your app'
      @param.define 'app.manifest', flag: 'm',
                                    description: 'path to your app.way file'
      @param.define :debug,         flag: 'd',
                                    description: 'print debug info to stdout',
                                    default: false
      @param.define :version,       flag: 'v',
                                    description: 'print version info'
      @param.read global_config if File.exists? global_config
      @param.read local_config if File.exists? local_config
      @param.use(:commandline)
      @param.resolve!
      self
    end

    def print_help!
      reload!
      @param[:help] = true
      @param.resolve!
      self
    end

    def [] key
      if @param
        @param[key]
      else
        nil
      end
    end

    def rest
      if @param
        @param.rest
      else
        []
      end
    end

    def to_hash
      if @param
        @param.to_hash
      else
        {}
      end
    end

    def global_config
      ENV['XWAY_CONFIG'] || File.join(ENV['HOME'], '.xway')
    end

    def local_config
      File.join(Dir.pwd, '.xway')
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
xway-0.0.3.beta lib/xway/parameter.rb
xway-0.0.2.beta lib/xway/parameter.rb