Sha256: f0cfc951744a9ce42e817a5588f1ff417ae19e20354f4239ff4680fb4be45bd2

Contents?: true

Size: 1.55 KB

Versions: 8

Compression:

Stored size: 1.55 KB

Contents

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

module PoolParty
  class Optioner
    include Configurable
    include MethodMissingSugar
        
    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 parent
      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

8 entries across 8 versions & 2 rubygems

Version Path
auser-poolparty-0.2.15 lib/poolparty/helpers/optioner.rb
auser-poolparty-0.2.3 lib/poolparty/helpers/optioner.rb
auser-poolparty-0.2.4 lib/poolparty/helpers/optioner.rb
auser-poolparty-0.2.5 lib/poolparty/helpers/optioner.rb
auser-poolparty-0.2.6 lib/poolparty/helpers/optioner.rb
auser-poolparty-0.2.8 lib/poolparty/helpers/optioner.rb
auser-poolparty-0.2.9 lib/poolparty/helpers/optioner.rb
poolparty-0.2.6 lib/poolparty/helpers/optioner.rb