Sha256: 365dc2bc1431ac7c999d1795e8444472e9324e8e9f339499f4654632d751c61a

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

require 'optparse' 
require 'rdoc/usage'
require 'ostruct'
require 'date'

module PoolParty
  class Optioner
    include Configurable
    
    attr_reader :options
    
    def initialize(args=[], opts={}, &block)
      @arguments = args
      @parse_options = opts[:parse_options] ? opts[:parse_options] : true
      
      set_default_options
      parse_options(&block) if @parse_options
      self
    end
    
    def set_default_options
      @options = {}
      @options[:verbose] = false
      @options[:quiet] = false
      @options[:version] = PoolParty::VERSION::STRING
    end
    
    def parse_options(&blk)
      opts = OptionParser.new 
      opts.banner = "Usage: pool [command] [options]"

      opts.separator ""
      opts.separator "Options:"
      
      opts.on('-V', '--version', 'Display the version')    { output_version ; exit 0 }
      opts.on('-v', '--verbose', 'Be verbose')    { @options[:verbose] = true }  
      opts.on('-s [file]', '--spec-file [file]', 'Set the spec file')      { |file| self.spec file }
      opts.on('-t', '--test', 'Testing mode')    { self.testing "true" }
                  
      blk.call(opts, self) if blk
      
      opts.on_tail("-h", "--help", "Show this message") do
        puts opts
        exit
      end
      
      opts.parse!(@arguments)
      
      process_options      
      output_options if verbose
    end
    def process_options
      @options[:verbose] = false if @options[:quiet]
    end
        
    def output_version
      puts version
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
auser-poolparty-0.2.2 lib/poolparty/helpers/optioner.rb