Class: Scelint::CLI
- Inherits:
-
Thor
- Object
- Thor
- Scelint::CLI
- Defined in:
- lib/scelint/cli.rb
Overview
SCELint CLI
Constant Summary collapse
- DEFAULTS_FILE =
'.scelint'
Class Method Summary collapse
- .exit_on_failure? ⇒ Boolean
-
.load_defaults ⇒ Object
Load default arguments from .scelint in the current directory.
-
.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
lintcommand.
Instance Method Summary collapse
Class Method Details
.exit_on_failure? ⇒ Boolean
9 10 11 |
# File 'lib/scelint/cli.rb', line 9 def self.exit_on_failure? true end |
.load_defaults ⇒ Object
Load default arguments from .scelint in the current directory. Each non-blank, non-comment line may contain one or more arguments.
17 18 19 20 21 22 |
# File 'lib/scelint/cli.rb', line 17 def self.load_defaults return [] unless File.exist?(DEFAULTS_FILE) File.readlines(DEFAULTS_FILE, chomp: true) .reject { |line| line.strip.empty? || line.strip.start_with?('#') } .flat_map(&:split) 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.
26 27 28 29 30 31 32 |
# File 'lib/scelint/cli.rb', line 26 def self.start(given_args = ARGV, config = {}) args = load_defaults + 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
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 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/scelint/cli.rb', line 41 def lint(*paths) paths = ['.'] if paths.nil? || paths.empty? lint = Scelint::Lint.new(paths, logger: logger, allow_reserved_words: [:allow_reserved_words]) 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 = "Checked #{count} files." if lint.errors.empty? += ' No errors.' exit_code = 0 else += " #{lint.errors.count} errors." exit_code = 1 end unless lint.warnings.empty? += " #{lint.warnings.count} warnings." exit_code = 1 if [:strict] end += " #{lint.notes.count} notes." unless lint.notes.empty? logger.info exit exit_code rescue => e logger.fatal e. end |