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



58
59
60
# File 'lib/dotbox/cli.rb', line 58

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

Instance Method Details

#add(*pathes) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dotbox/cli.rb', line 16

def add(*pathes)
  check_setup
  @record = Record.new
  pathes.each do |path|
    path = ::File.expand_path(path)
    if ::File.exists?(path)
      file = File.new(path)
      file.backup
      @record.add file
    else
      say "#{path} not exists."
    end
  end
end

#remove(*pathes) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dotbox/cli.rb', line 32

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



49
50
51
52
53
54
55
56
# File 'lib/dotbox/cli.rb', line 49

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

#setupObject



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

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