Sha256: 20c760b08280945e4f9ffd32c518c923b0d2cbdf0c5078f2127fdf41e686253b

Contents?: true

Size: 1.62 KB

Versions: 9

Compression:

Stored size: 1.62 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 = parse_args(args)
      @parse_options = opts[:parse_options] ? opts[:parse_options] : true
      
      set_default_options
      parse_options(&block) if @parse_options
      self
    end
    
    def parse_args(argv, safe=[])
      argv
    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.dup)
      
      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

9 entries across 9 versions & 2 rubygems

Version Path
auser-poolparty-0.2.16 lib/poolparty/helpers/optioner.rb
auser-poolparty-0.2.20 lib/poolparty/helpers/optioner.rb
auser-poolparty-0.2.21 lib/poolparty/helpers/optioner.rb
auser-poolparty-0.2.22 lib/poolparty/helpers/optioner.rb
auser-poolparty-0.2.23 lib/poolparty/helpers/optioner.rb
auser-poolparty-0.2.24 lib/poolparty/helpers/optioner.rb
auser-poolparty-0.2.25 lib/poolparty/helpers/optioner.rb
auser-poolparty-0.2.26 lib/poolparty/helpers/optioner.rb
poolparty-0.2.18 lib/poolparty/helpers/optioner.rb