Class: Glacier::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/glacier/cli.rb,
lib/glacier/cli/version.rb

Constant Summary collapse

CHUNK_SIZE =

8 MB

1024 * 1024 * 8
LOCAL_STORE =
"#{ENV['HOME']}/.glacier"
VERSION =
"0.0.2"

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.



16
17
18
19
20
# File 'lib/glacier/cli.rb', line 16

def initialize(args)
  @files = []
  @directories = []
  parse_options args
end

Instance Method Details

#runObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/glacier/cli.rb', line 22

def run
  @directories.each do |directory|
    Find.find(directory == '.' ? Dir.pwd : directory) do |path|
      dot = File.basename(path).start_with? '.'
      if FileTest.directory? path
        # completely skip 'dot' directories
        Find.prune if dot
      else
        # ignore dotfiles
        @files << path unless dot
      end
    end
  end

  @files.each do |file|
    basename = File.basename(file)
    if uploaded_files.include? basename
      puts "Skipping #{file} (already uploaded)"
    else
      vault.archives.create body: File.new(file), multipart_chunk_size: CHUNK_SIZE, description: basename
      File.write LOCAL_STORE, "#{basename}\n", mode: 'a'
      puts "Uploaded #{file}"
    end
  end
end