Class: SshKeySwitcher::Options::Delete

Inherits:
Object
  • Object
show all
Extended by:
Contains, Utils
Defined in:
lib/ssh_key_switcher/options/delete.rb

Constant Summary

Constants included from Contains

Contains::SERVER_NAMES, Contains::SSH_DIR, Contains::STRING_DETECT_OPENSSH_KEY

Class Method Summary collapse

Class Method Details

.del(path_open_ssh_keys) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ssh_key_switcher/options/delete.rb', line 21

def del(path_open_ssh_keys)
  is_no = prompt.no?('Are you sure you want to delete it permanently?')

  if is_no
    prompt.say('Cancelled!')
  else
    path_open_ssh_keys.each do |path|
      SshKeySwitcher::Utils::SshAgent.del(path)
      Cmd.exec("rm #{path}")
      Cmd.exec("rm #{path}.pub")
    end
    prompt.ok('OpenSSH key removed successfully!')
  end
end

.display_selectObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ssh_key_switcher/options/delete.rb', line 7

def display_select
  keys = Helper.find_open_ssh_keys
  if keys.empty?
    prompt.error('No OpenSSH keys found in ~/.ssh')
    nil
  else
    msg = 'Choose the OpenSSH keys to REMOVE. Press [CTRL+C] to exit.'
    prompt.multi_select(msg, select_options) do |menu|
      menu.enum '.'
      select_choices(menu, keys)
    end
  end
end