Class: Giticious::Cli::Repo

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

Instance Method Summary collapse

Instance Method Details

#create(name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/giticious/cli/repo.rb', line 6

def create(name)
  begin
    Giticious::Service::Repository.new.create(name)
    puts "The repository has been created"
    list()
  rescue => e
    $stderr.puts e.message
    exit 1
  end
end

#delete(name) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/giticious/cli/repo.rb', line 31

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

#import(url) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/giticious/cli/repo.rb', line 18

def import(url)
  begin
    puts "Importing #{url}..."
    Giticious::Service::Repository.new.import(url)
    puts "Repository imported"
    list()
  rescue => e
    $stderr.puts e.message
    exit 1
  end
end

#listObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/giticious/cli/repo.rb', line 41

def list
  begin
    rows = []

    Giticious::Service::Repository.new.list.each do |repo|
      rows << [ repo.name, repo.path, "#{Etc.getlogin}@<your-server-url>:#{repo.name}.git" ]
    end

    table = Terminal::Table.new :headings => ["Name", "Path", "SSH URL"], :rows => rows
    puts table
  rescue => e
    $stderr.puts e.message
    exit 1
  end
end

#permit(repo, username, permissions) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/giticious/cli/repo.rb', line 75

def permit(repo, username, permissions)
  begin
    if Giticious::Service::Repository.new.add_user(repo, username, permissions) == false
      $stderr.puts "Could not grant permissions to this user"
      exit 1
    end

    puts "Permission granted!"

    users(repo)
  rescue => e
    $stderr.puts e.message
    exit 1
  end
end

#revoke(repo, username) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/giticious/cli/repo.rb', line 92

def revoke(repo, username)
  begin
    if Giticious::Service::Repository.new.delete_user(repo, username) == false
      $stderr.puts "Could not revoke permissions from this user"
      exit 1
    end

    puts "Permission revoked!"

    users(repo)
  rescue => e
    $stderr.puts e.message
    exit 1
  end
end

#users(repo) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/giticious/cli/repo.rb', line 58

def users(repo)
  begin
    rows = []

    Giticious::Service::Repository.new.permissions(repo).each do |perm|
      rows << [ repo, perm.user.username, perm.perm_read, perm.perm_write ]
    end

    table = Terminal::Table.new :headings => ["Repository", "User", "Read", "Write"], :rows => rows
    puts table
  rescue => e
    $stderr.puts e.message
    exit 1
  end
end