Class: GithubControl::Actions::Collaborators

Inherits:
GithubControl::Action show all
Defined in:
lib/github-control/actions/collaborators.rb

Instance Method Summary collapse

Methods inherited from GithubControl::Action

#initialize, #options, register, set

Constructor Details

This class inherits a constructor from GithubControl::Action

Instance Method Details

#add_options(parser) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/github-control/actions/collaborators.rb', line 6

def add_options(parser)
  parser.on("-R name", "--repository name", "The repository on Github") do |repository_name|
    options[:repository_name] = repository_name
  end

  parser.on("-U name", "--user name", "The user on Github") do |user_name|
    options[:user_name] = user_name
  end
end

#callObject



16
17
18
19
20
21
22
# File 'lib/github-control/actions/collaborators.rb', line 16

def call
  puts "Listing the collaborators of #{repository.full_name}"
  puts "-" * 40
  repository.collaborators.each do |user|
    puts "- #{user.name}"
  end
end

#repositoryObject



24
25
26
# File 'lib/github-control/actions/collaborators.rb', line 24

def repository
  user.repositories.get(options[:repository_name] || raise(ProblemWithOptions, "Please specify a repository"))
end

#userObject



28
29
30
31
32
33
34
# File 'lib/github-control/actions/collaborators.rb', line 28

def user
  if options[:user_name]
    @cli.console.user_for(options[:user_name])
  else
    @cli.console.current_user
  end
end