Class: LinuxHub::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/linux-hub/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ CLI

Returns a new instance of CLI.



3
4
5
6
7
8
9
10
# File 'lib/linux-hub/cli.rb', line 3

def initialize(config)
  @organization = config["organisation"]
  @team = config["team"]
  @groups = config["groups"]

  Github.instance.access_token = config["access_token"]
  Octokit.auto_paginate = true
end

Instance Method Details

#create_usersObject



28
29
30
# File 'lib/linux-hub/cli.rb', line 28

def create_users
  add_users(github_users)
end

#listObject



12
13
14
# File 'lib/linux-hub/cli.rb', line 12

def list
  puts github_users.collect(&:authorized_keys)
end

#sync_usersObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/linux-hub/cli.rb', line 16

def sync_users
  linux_users = LinuxUser.users_in_group
  linux_usernames = linux_users.collect(&:username)
  github_usernames = github_users.collect(&:username)
  # Equivalent to github_users - linux_users
  users_to_add = github_users.reject { |u| linux_usernames.include? u.username }
  # Equivalent to linux_users - github_users
  users_to_delete = linux_users.reject { |u| github_usernames.include? u.username }
  add_users(users_to_add)
  delete_users(users_to_delete)
end