Class: Giticious::Cli::Pubkey

Inherits:
Thor
  • Object
show all
Defined in:
lib/giticious/cli/pubkey.rb

Instance Method Summary collapse

Instance Method Details

#add(username, pubkey) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/giticious/cli/pubkey.rb', line 6

def add(username, pubkey)
  begin
    if Giticious::Service::User.new.exists?(username) == false
      $stderr.puts "A user with this name does not exist"
      exit 1
    end

    if Giticious::Service::Pubkey.new.add(username, pubkey)
      puts "Public key \"#{pubkey.split(//).last(80).join}\" for user #{username} has been added!"
    end

    list(username)
  rescue => e
    $stderr.puts e.message
    exit 1
  end
end

#delete(pubkey) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/giticious/cli/pubkey.rb', line 25

def delete(pubkey)
  begin
    Giticious::Service::Pubkey.new.delete(pubkey)
  rescue => e
    $stderr.puts e.message
    exit 1
  end
end

#list(username) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/giticious/cli/pubkey.rb', line 35

def list(username)
  begin
    rows = []

    Giticious::Service::Pubkey.new.user_pubkeys(username).each do |pubkey|
      rows << [ username, pubkey.split(//).last(80).join ]
    end


    table = Terminal::Table.new :headings => ["Username", "Public key (last 80 chars)"], :rows => rows
    puts table
  rescue => e
    $stderr.puts e.message
    exit 1
  end
end