Class: Dotbox::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootObject



69
70
71
# File 'lib/dotbox/cli.rb', line 69

def self.source_root
  ::File.dirname(::File.expand_path('../../../bin/dotbox', __FILE__))
end

Instance Method Details

#add(*pathes) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dotbox/cli.rb', line 17

def add(*pathes)
  check_setup
  @record = Record.new
  pathes.each do |path|
    if Dir[path].empty?
      die "#{path} not exists."
    end
    Dir[path].each do |p|
      begin
        p = ::File.expand_path(p)
        file = File.new(p)
        file.backup
        @record.add file
      rescue => ex
        die ex.message
      end
    end
  end
end

#remove(*pathes) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/dotbox/cli.rb', line 38

def remove(*pathes)
  check_setup
  @record = Record.new
  pathes.each do |path|
    path = ::File.expand_path(path)
    file = File.new(path)
    if !::File.exists?(path)
      die "#{path} not exists."
    elsif !file.backuped?
      die "#{path} is not backuped."
    end
    file.remove
    @record.remove file
  end
end

#restoreObject



55
56
57
58
59
60
61
62
# File 'lib/dotbox/cli.rb', line 55

def restore
  check_setup
  @record = Record.new
  @record.each do |path|
    file = File.new(path)
    file.restore
  end
end

#setupObject



11
12
13
14
# File 'lib/dotbox/cli.rb', line 11

def setup
  dropbox_path = ask('Enter dropbox folder location:').strip
  Dotbox::Config.new(Dotbox::CONFIG_FILE, dropbox_path)
end

#versionObject



65
66
67
# File 'lib/dotbox/cli.rb', line 65

def version
  puts Dotbox::VERSION::STRING
end