Sha256: 5245c954a3449fca219f702ccd4137c6671ffa4982e77ae2ef35297ce1857465

Contents?: true

Size: 1.43 KB

Versions: 3

Compression:

Stored size: 1.43 KB

Contents

module Downer
  class Application
    
    attr_accessor :output
    attr_reader :options
    
    def initialize(output = nil)
      @output = (output) ? output : $stdout
      @options = nil
    end
    
    def run!(*arguments)
      @options = Downer::Options.new(arguments)
      download_options = {}
      

      
      # begin analysis of arguments
      if @options[:invalid_argument]
        @output.puts @options[:invalid_argument]
        @options[:show_help] = true
      end
      
      if @options[:images_only]
        print_image_only_message
        download_options[:images_only] = true
      end
      
      # Immediately exit if this will never complete
      return exit_with_help_banner if @options[:file_manifest].nil?
      return exit_with_help_banner if @options[:target_directory].nil?
      return exit_with_help_banner if @options[:show_help]
      

      begin
        manager = Downer::DownloadManager.new(@options[:file_manifest], @options[:target_directory], @output, download_options)
        manager.start
        return 0
      rescue Downer::WriteFailed
        @output.puts %Q{Insufficient permissions to write to directory}
        return 1
      end
    end
    
    private

    def print_image_only_message
      @output.puts "Images only filter selected...downloading PNG,JPG,GIF, and TIFF files"
    end
    
    def exit_with_help_banner
      @output.puts @options.opts.banner
      return 1
    end
    
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
downer-0.3.2 lib/downer/application.rb
downer-0.3.1 lib/downer/application.rb
downer-0.3.0 lib/downer/application.rb