Class: CodeInventory::CLI::App

Inherits:
Thor
  • Object
show all
Defined in:
lib/codeinventory_plugin.rb

Instance Method Summary collapse

Instance Method Details

#github(org) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/codeinventory_plugin.rb', line 15

def github(org)
  unless !options["access-token"].nil? ^ !options["client-credentials"].nil? ^ !options["login"].nil?
    puts "One authentication method is required (-a, -c, or -l)"
    exit 1
  end
  auth = {}
  if !options["access-token"].nil?
    auth = { access_token: options["access-token"] }
  elsif !options["client-credentials"].nil?
    values = options["client-credentials"].split(":")
    unless values.count == 2
      puts "You must provide client credentials in the format CLIENT_ID:CLIENT_SECRET"
      exit 1
    end
    auth = { client_id: values[0], client_secret: values[1] }
  elsif !options["login"].nil?
    values = options["login"].split(":")
    unless values.count == 2
      puts "You must provide a login in the format USERNAME:PASSWORD"
      exit 1
    end
    auth = { login: values[0], password: values[1] }
  end
  source = CodeInventory::GitHub::Source.new(auth, org, overrides: options[:overrides], exclude: options[:exclude])
  inventory = CodeInventory::Inventory.new(source)
  agency = options["agency-name"] || org
  output = inventory.generate(agency, "1.0.1")
  puts JSON.pretty_generate(output)
end