Class: Recluse::CLI::Roots

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

Overview

Roots related commands.

Instance Method Summary collapse

Instance Method Details

#add(name, *roots) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/recluse/cli/roots.rb', line 10

def add(name, *roots)
  uconf = UserConfig.new '.recluse'
  unless uconf.exist?("#{name}.yaml")
    puts "Profile #{name} doesn't exist"
    exit(-1)
  end
  profile = uconf["#{name}.yaml"]
  if profile.key?('roots')
    profile['roots'] += roots
  else
    profile['roots'] = roots
  end
  profile.save
end

#clear(name) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/recluse/cli/roots.rb', line 37

def clear(name)
  uconf = UserConfig.new '.recluse'
  unless uconf.exist?("#{name}.yaml")
    puts "Profile #{name} doesn't exist"
    exit(-1)
  end
  profile = uconf["#{name}.yaml"]
  profile['roots'] = []
  profile.save
end

#list(name) ⇒ Object



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

def list(name)
  uconf = UserConfig.new '.recluse'
  unless uconf.exist?("#{name}.yaml")
    puts "Profile #{name} doesn't exist"
    exit(-1)
  end
  profile = uconf["#{name}.yaml"]
  profile['roots'].each { |root| puts root } if profile.key?('roots')
end

#remove(name, *roots) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/recluse/cli/roots.rb', line 25

def remove(name, *roots)
  uconf = UserConfig.new '.recluse'
  unless uconf.exist?("#{name}.yaml")
    puts "Profile #{name} doesn't exist"
    exit(-1)
  end
  profile = uconf["#{name}.yaml"]
  return unless profile.key?('roots')
  profile['roots'] -= roots
  profile.save
end