require "down_universe/version" require_relative "./down_universe.rb" require "optparse" class Application attr_accessor :type, :user, :password, :output, :url include DownUniverse::Downloadable def run # Parsing command line arguments OptionParser.new do |opts| opts.banner = "Usage: down_universe [options] url output.It Downloads the given 'url' and saves it in 'output' file" opts.on("--user", "Sets the HTTP or FTP user.") do |user| self.user = user end opts.on("--password", "Sets the HTTP or FTP password.") do |password| self.password = password end opts.on("-t", "--type DOWNLOAD_TYPE", "Sets the download type available types are 'torrent', 'http' or 'ftp'. 'http' is the default value.") do |type| self.type = type end end.parse! # Get the output path and url from the ARGV variable self.output = ARGV.pop self.url = ARGV.pop # Set default download type to http self.type = 'http' case self.type.downcase when 'http' http_download(self.url, self.output, self.user, self.password) when 'ftp' puts "Not implemented yet." when 'torrent' puts "Not implemented yet." else puts "The 'type' option could be one of the 'http', 'ftp' or 'torrent' options." end end end