Class: Gerd::CLI

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

Instance Method Summary collapse

Instance Method Details

#apply(organisation) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/gerd/cli.rb', line 47

def apply(organisation)
  token = options[:token] if options[:token]
  client = Gerd::GHClient.create(token)
  auditor = Gerd::Audit.new(client, organisation)
  expected_state = Gerd::Model::GithubState.from_json(File.read(options[:file]))
  actual_state = Gerd::Model::GithubState.new(auditor.full_audit)
  validator = Gerd::Validation::Validator.new(expected_state, actual_state)
  actions = validator.collect_actions.flatten
  actions.each do | action |
    action.invoke(client, options)
  end
end

#audit(organisation) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/gerd/cli.rb', line 18

def audit(organisation)
  token = options[:token] if options[:token]
  client = Gerd::GHClient.create(token)
  auditor = Gerd::Audit.new(client, organisation)
  content = auditor.full_audit
  formatter = Gerd::Formatters.find_formatter(options[:file])
  formatter.print(content, options)
end

#exec(script) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/gerd/cli.rb', line 63

def exec(script)
  current_state = Gerd::Model::GithubState.from_json(File.read(options[:input]))
  script = File.read(script)
  exec_helper = Gerd::Helpers::Exec.new(script)
  exec_helper.exec(current_state)
  formatter = Gerd::Formatters.find_formatter(options[:output])
  formatter.print(current_state.serialize, options)
  
end

#validate(organisation) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gerd/cli.rb', line 31

def validate(organisation)
  token = options[:token] if options[:token]
  client = Gerd::GHClient.create(token)
  auditor = Gerd::Audit.new(client, organisation)
  expected_state = Gerd::Model::GithubState.from_json(File.read(options[:expected]))
  actual_state = Gerd::Model::GithubState.new(auditor.full_audit)
  validator = Gerd::Validation::Validator.new(expected_state, actual_state)
  content = validator.validate
  formatter = Gerd::Formatters.find_formatter(options[:file])
  formatter.print(content, options)
end