Class: PomPomPom::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/pompompom/cli.rb

Defined Under Namespace

Classes: EchoLogger

Instance Method Summary collapse

Constructor Details

#initialize(stdin, stdout, stderr, options = {}) ⇒ Cli

Returns a new instance of Cli.



6
7
8
9
10
11
12
13
# File 'lib/pompompom/cli.rb', line 6

def initialize(stdin, stdout, stderr, options={})
  @config = Config.new(options)
  @config.load!
  @stdin, @stdout, @stderr = stdin, stdout, stderr
  @status_logger = EchoLogger.new(@stderr)
  @downloader = CachingDownloader.new(@config.cache_dir, Downloader.new)
  @resolver = options[:resolver]
end

Instance Method Details

#run!(*args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/pompompom/cli.rb', line 15

def run!(*args)
  if args.empty?
    print_usage
    return 1
  end
  
  resolver = create_resolver

  @config.create_file! unless @config.file_exists?
  create_lib_directory!

  @status_logger.info("Determining transitive dependencies...")

  dependencies = parse_dependencies(args)
  dependencies = resolver.find_transitive_dependencies(*dependencies)
  dependencies = dependencies.reject { |d| File.exists?(File.join(@config.target_dir, d.jar_file_name)) }

  if dependencies.empty?
    @status_logger.info('All dependencies are met')
  else
    dependencies.each do |dependency|
      @status_logger.info(%(Downloading "#{dependency.to_dependency.to_s}"))
      resolver.download!(@config.target_dir, false, dependency)
    end
  end
  
  return 0
rescue => e
  @status_logger.warn(%(Warning: #{e.message}))
  return 1
end