Class: Recluse::CLI::Profile

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

Overview

Commands to edit/create/delete profiles.

Instance Method Summary collapse

Instance Method Details

#create(name, email, *roots) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/recluse/cli/profile.rb', line 19

def create(name, email, *roots)
  uconf = UserConfig.new '.recluse'
  if uconf.exist?("#{name}.yaml")
    puts "Profile #{name} already exists"
    exit(-1)
  end
  begin
    profile = Recluse::Profile.new(
      name,
      roots,
      email,
      blacklist: options['blacklist'],
      whitelist: options['whitelist'],
      internal_only: options['internal_only'],
      scheme_squash: options['scheme_squash'],
      redirect: options['redirect']
    )
    profile.save
  rescue ProfileError => e
    puts e
    exit(-1)
  end
end

#edit(name) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/recluse/cli/profile.rb', line 59

def edit(name)
  begin
    profile = Recluse::Profile.load name
  rescue ProfileError => e
    puts e
    exit(-1)
  end
  profile.roots = options['roots'] if options.key? 'roots'
  profile.blacklist = options['blacklist'] if options.key? 'blacklist'
  profile.whitelist = options['whitelist'] if options.key? 'whitelist'
  profile.internal_only = options['internal_only'] if options.key? 'internal_only'
  profile.scheme_squash = options['scheme_squash'] if options.key? 'scheme_squash'
  profile.redirect = options['redirect'] if options.key? 'redirect'
  profile.email = options['email'] if options.key? 'email'
  profile.save
end

#info(name) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/recluse/cli/profile.rb', line 101

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

#listObject



93
94
95
96
97
98
99
# File 'lib/recluse/cli/profile.rb', line 93

def list
  uconf = UserConfig.new '.recluse'
  files = uconf.list_in_directory '.'
  files.each do |file|
    puts file.gsub(/\.yaml$/, '')
  end
end

#remove(name) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/recluse/cli/profile.rb', line 43

def remove(name)
  uconf = UserConfig.new '.recluse'
  if uconf.exist?("#{name}.yaml")
    uconf.delete "#{name}.yaml"
  else
    exit(-1)
  end
end

#rename(old_name, new_name) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/recluse/cli/profile.rb', line 76

def rename(old_name, new_name)
  uconf = UserConfig.new '.recluse'
  if uconf.exist?("#{new_name}.yaml")
    puts "Profile #{new_name} already exists"
    exit(-1)
  end
  return unless uconf.exist?("#{old_name}.yaml")
  old_profile = uconf["#{old_name}.yaml"]
  old_profile['name'] = new_name
  new_profile = uconf["#{new_name}.yaml"]
  old_profile.each do |key, value|
    new_profile[key] = value
  end
  new_profile.save
  uconf.delete "#{old_name}.yaml"
end