Class: Recluse::CLI::Profile
- Inherits:
-
Thor
- Object
- Thor
- Recluse::CLI::Profile
- Defined in:
- lib/recluse/cli/profile.rb
Overview
Commands to edit/create/delete profiles.
Instance Method Summary collapse
- #create(name, email, *roots) ⇒ Object
- #edit(name) ⇒ Object
- #info(name) ⇒ Object
- #list ⇒ Object
- #remove(name) ⇒ Object
- #rename(old_name, new_name) ⇒ Object
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: ['blacklist'], whitelist: ['whitelist'], internal_only: ['internal_only'], scheme_squash: ['scheme_squash'], redirect: ['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 = ['roots'] if .key? 'roots' profile.blacklist = ['blacklist'] if .key? 'blacklist' profile.whitelist = ['whitelist'] if .key? 'whitelist' profile.internal_only = ['internal_only'] if .key? 'internal_only' profile.scheme_squash = ['scheme_squash'] if .key? 'scheme_squash' profile.redirect = ['redirect'] if .key? 'redirect' profile.email = ['email'] if .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 |
#list ⇒ Object
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 |