Class: ArtifactTools::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/artifact_tools/downloader.rb

Overview

Downloader allows the user to fetch files from a store specified. All this information is provided by ConfigFile.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = { verify: true, force: false }) ⇒ Downloader

Downloads requested files

Parameters:

  • args (Hash) (defaults to: { verify: true, force: false })

    the arguments for downloading artifacts



22
23
24
25
26
# File 'lib/artifact_tools/downloader.rb', line 22

def initialize(args = { verify: true, force: false })
  config = load_config(args[:config_file])
  c = ArtifactTools::Client.new(config: config.config, user: args[:user])
  c.fetch(dest: args[:dest_dir], verify: args[:verify], match: args[:match], force: args[:force])
end

Class Method Details

.parse(arguments) ⇒ Object

Parse command line options to options suitable to Downloader.new

Parameters:

  • arguments (Array(String))

    Command line options to parse and use. Hint: pass ARGV

Raises:

  • (OptionParser::MissingArgument)


64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/artifact_tools/downloader.rb', line 64

def self.parse(arguments)
  options = @default_opts
  arguments << '-h' if arguments.empty?
  OptionParser.new do |opts|
    opts.banner = "Usage: #{__FILE__} [options]"
    @parse_opts_handlers.each do |args, handler|
      opts.on(*args) { |v|  handler.call(v, options, opts) }
    end
  end.parse!(arguments)

  raise OptionParser::MissingArgument, 'Missing -c/--configuration option' unless options.key?(:config_file)

  options
end