Class: CocoaCache::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoacache/command.rb

Class Method Summary collapse

Class Method Details

.get_core(factory, argv) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cocoacache/command.rb', line 23

def self.get_core(factory, argv)
  return factory.new(
    :origin_specs_dir => (
      self.parse_argument(argv, "--origin") \
      or "$HOME/.cocoapods/repos/master/Specs"
    ),
    :cache_specs_dir => (
      self.parse_argument(argv, "--cache") \
        or "Specs"
    ),
    :podfile_path => (
      self.parse_argument(argv, "--podfile") \
      or "Podfile.lock"
    ),
  )
end

.helpObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cocoacache/command.rb', line 40

def self.help
  puts <<~HELP
  Usage: cocoacache COMMAND [options]

  Commands:
    save        Copy specs from the origin Specs to cache directory.
    restore     Copy the cached Specs back to the origin directory.

  Options:
    --origin <value>    The origin Specs directory. Defaults to $HOME/.cocoapods/repos/master/Specs
    --cache <value>     Where to cache the Specs. Defaults to ~/Specs
    --podfile <value>   The path for the Podfile.lock. Defaults to ~/Podfile.lock
  HELP
end

.parse_argument(argv, name) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cocoacache/command.rb', line 55

def self.parse_argument(argv, name)
  index = argv.index(name)
  if index.nil?
    return nil
  end

  value = argv[index + 1]
  if value.nil? or value.start_with?('--')
    raise Exception("[!] Insufficient value for option '#{name}'".red)
  end

  return value
end

.run(core_factory, argv) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/cocoacache/command.rb', line 5

def self.run(core_factory, argv)
  case argv[0]
  when "save"
    core = self.get_core(core_factory, argv)
    core.save()

  when "restore"
    core = self.get_core(core_factory, argv)
    core.restore()

  when "--version"
    puts CocoaCache::VERSION

  else
    self.help
  end
end