Class: Scelint::CLI

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

Overview

SCELint CLI

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/scelint/cli.rb', line 9

def self.exit_on_failure?
  true
end

.start(given_args = ARGV, config = {}) ⇒ Object

When the first argument is not a known subcommand or an option flag, treat all arguments as paths for the default ‘lint` command.



15
16
17
18
19
20
21
# File 'lib/scelint/cli.rb', line 15

def self.start(given_args = ARGV, config = {})
  args = given_args
  if args.first && !args.first.start_with?('-') && !all_commands.key?(args.first)
    args = ['lint'] + args
  end
  super(args, config)
end

Instance Method Details

#lint(*paths) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/scelint/cli.rb', line 29

def lint(*paths)
  paths = ['.'] if paths.nil? || paths.empty?
  lint = Scelint::Lint.new(paths, logger: logger)

  count = lint.files.count

  if count.zero?
    logger.error 'No SCE data found.'
    exit 0
  end

  lint.errors.each do |error|
    logger.error error
  end

  lint.warnings.each do |warning|
    logger.warn warning
  end

  lint.notes.each do |note|
    logger.info note
  end

  message = "Checked #{count} files."
  if lint.errors.empty?
    message += '  No errors.'
    exit_code = 0
  else
    message += "  #{lint.errors.count} errors."
    exit_code = 1
  end

  unless lint.warnings.empty?
    message += "  #{lint.warnings.count} warnings."
    exit_code = 1 if options[:strict]
  end

  message += " #{lint.notes.count} notes." unless lint.notes.empty?

  logger.info message
  exit exit_code
rescue => e
  logger.fatal e.message
end