Class: CiCache::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/ci-cache/cli.rb

Constant Summary collapse

VALID_COMMANDS =
['get', 'set']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv = nil) ⇒ CLI

Returns a new instance of CLI.



16
17
18
19
20
# File 'lib/ci-cache/cli.rb', line 16

def initialize(argv = nil)
  @argv    = argv || ARGV
  @options = {}
  self.fold_count = 0
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



11
12
13
# File 'lib/ci-cache/cli.rb', line 11

def argv
  @argv
end

#commandObject

Returns the value of attribute command.



12
13
14
# File 'lib/ci-cache/cli.rb', line 12

def command
  @command
end

#fold_countObject

Returns the value of attribute fold_count.



12
13
14
# File 'lib/ci-cache/cli.rb', line 12

def fold_count
  @fold_count
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/ci-cache/cli.rb', line 11

def options
  @options
end

Class Method Details

.run(argv) ⇒ Object



7
8
9
# File 'lib/ci-cache/cli.rb', line 7

def self.run(argv)
  new(argv).run
end

Instance Method Details

#archive_pathObject



70
71
72
# File 'lib/ci-cache/cli.rb', line 70

def archive_path
  Pathname("#{tmp_folder}/#{cache_archive_name}")
end

#cache_archive_nameObject



58
59
60
# File 'lib/ci-cache/cli.rb', line 58

def cache_archive_name
  "#{name}.tar.gz"
end

#cache_hash_file_nameObject



62
63
64
# File 'lib/ci-cache/cli.rb', line 62

def cache_hash_file_name
  "#{name}.sha2"
end

#contentObject



43
44
45
46
# File 'lib/ci-cache/cli.rb', line 43

def content
  error("No valid content provided") unless options[:content]
  Pathname(options[:content])
end

#fold(message) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/ci-cache/cli.rb', line 29

def fold(message)
  self.fold_count += 1
  print "travis_fold:start:ci-cache.#{fold_count}\r" if options[:fold]
  puts "\e[33m#{message}\e[0m"
  yield
ensure
  print "\ntravis_fold:end:ci-cache.#{fold_count}\r" if options[:fold]
end

#hash_fileObject



48
49
50
51
# File 'lib/ci-cache/cli.rb', line 48

def hash_file
  error("No hash file provided") unless options[:hash_file]
  Pathname(options[:hash_file]).expand_path
end

#log(message) ⇒ Object



78
79
80
# File 'lib/ci-cache/cli.rb', line 78

def log(message)
  $stderr.puts(message)
end

#nameObject



38
39
40
41
# File 'lib/ci-cache/cli.rb', line 38

def name
  error("No valid name provided") unless options[:name]
  options[:name]
end

#old_hash_fileObject



74
75
76
# File 'lib/ci-cache/cli.rb', line 74

def old_hash_file
  Pathname("#{tmp_folder}/#{cache_hash_file_name}")
end

#output_pathObject



53
54
55
56
# File 'lib/ci-cache/cli.rb', line 53

def output_path
  error("No output path provided") unless options[:output_path]
  Pathname(options[:output_path]).expand_path
end

#runObject



22
23
24
25
26
27
# File 'lib/ci-cache/cli.rb', line 22

def run
  parse!
  execute_command
rescue Error => error
  options[:debug] ? raise(error) : die(error.message)
end

#tmp_folderObject



66
67
68
# File 'lib/ci-cache/cli.rb', line 66

def tmp_folder
  Pathname("~").expand_path
end