Sha256: 88b3e12ab247d89541af53ef81e2c098809f8585c360db249b9b2178aa9c4502

Contents?: true

Size: 934 Bytes

Versions: 1

Compression:

Stored size: 934 Bytes

Contents

require 'optparse'

module Stowaway
  class Options
    DEFAULT_FILE_TYPES = %w{.jpg .gif .png .ico .js .css}
    
    attr_reader :path, :file_types
    
    def initialize(argv)
      @file_types = DEFAULT_FILE_TYPES
      parse(argv)
      @path = argv[0]
    end
    
    private

    def parse(argv) 
      OptionParser.new do |opts| 
        opts.banner = "Usage: stowaway [ options ] path/to/site" 
        
        opts.on("-t", "--types <TYPES>", String, "File types to search for (ex: .jpg .gif)") do |ext| 
          @file_types = ext.split(' ')
        end

        opts.on("-h", "--help", "Show this message") do
          puts opts 
          exit 
        end 
        
        begin 
          argv = ["-h"] if argv.empty? 
          opts.parse!(argv) 
        rescue OptionParser::ParseError => e 
          STDERR.puts e.message, "\n", opts 
          exit(-1) 
        end 
        
      end 
    end 
  end 
end 

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stowaway-0.1.9 lib/stowaway/options.rb