Class: Licit::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/licit/command.rb

Instance Method Summary collapse

Instance Method Details

#check(licenser) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/licit/command.rb', line 13

def check(licenser)
  has_errors = false
  (licenser.check_files | licenser.check_headers).each do |severity, file, message|
    puts message
    has_errors = true if severity == :error
  end
  exit (has_errors ? 1 : 0)
end

#find_file(probes) ⇒ Object



41
42
43
44
45
46
# File 'lib/licit/command.rb', line 41

def find_file probes
  probes.each do |file|
    return file if File.exist? file
  end
  nil
end

#fix(licenser) ⇒ Object



22
23
24
25
# File 'lib/licit/command.rb', line 22

def fix(licenser)
  licenser.fix_files
  licenser.fix_headers
end

#load_configObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/licit/command.rb', line 27

def load_config
  config_file = find_file ['licit.yml', 'config/licit.yml']
  unless config_file
    puts "Could not find licit.yml config file"
    exit 1
  end

  config = {}
  YAML.load_file(config_file).each do |key, value|
    config[key.to_sym] = value
  end
  config
end

#runObject



4
5
6
7
8
9
10
11
# File 'lib/licit/command.rb', line 4

def run
  licenser = Licit::Licenser.new load_config
  if ARGV[0] == 'fix'
    fix licenser
  else
    check licenser
  end
end