-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use `thor` gem for the CLI * Add quiet/verbose/debug options to the CLI * Bump minimum required Ruby version to 2.7.0 (oldest version we're testing with) * Accept `String` arguments to `new()` - Fixes #23 - Fixes #24
- Loading branch information
Showing
4 changed files
with
78 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,6 @@ | ||
#!/usr/bin/env ruby | ||
# frozen_string_literal: true | ||
|
||
require 'scelint' | ||
require 'scelint/cli' | ||
|
||
to_check = ARGV.empty? ? ['.'] : ARGV | ||
lint = Scelint::Lint.new(to_check) | ||
|
||
count = lint.files.count | ||
|
||
if count.zero? | ||
warn 'No SCE data found.' | ||
exit 0 | ||
end | ||
|
||
lint.errors.each do |error| | ||
warn error | ||
end | ||
|
||
lint.warnings.each do |warning| | ||
warn warning | ||
end | ||
|
||
message = "Checked #{count} files." | ||
if lint.errors.count == 0 | ||
message += ' No errors.' | ||
exit_code = 0 | ||
else | ||
message += " #{lint.errors.count} errors." | ||
exit_code = 1 | ||
end | ||
|
||
if lint.warnings.count > 0 | ||
message += " #{lint.warnings.count} warnings." | ||
end | ||
|
||
puts message | ||
exit exit_code | ||
Scelint::CLI.start(['lint'] + ARGV) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'scelint' | ||
require 'thor' | ||
require 'logger' | ||
|
||
# SCELint CLI | ||
class Scelint::CLI < Thor | ||
class_option :quiet, type: :boolean, aliases: '-q', default: false | ||
class_option :verbose, type: :boolean, aliases: '-v', default: false | ||
class_option :debug, type: :boolean, aliases: '-d', default: false | ||
|
||
desc 'lint PATH', 'Lint all files in PATH' | ||
def lint(*paths) | ||
paths = ['.'] if paths.nil? || paths.empty? | ||
lint = Scelint::Lint.new(paths) | ||
|
||
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 | ||
|
||
message = "Checked #{count} files." | ||
if lint.errors.count == 0 | ||
message += ' No errors.' | ||
exit_code = 0 | ||
else | ||
message += " #{lint.errors.count} errors." | ||
exit_code = 1 | ||
end | ||
|
||
if lint.warnings.count > 0 | ||
message += " #{lint.warnings.count} warnings." | ||
end | ||
|
||
logger.info message | ||
exit exit_code | ||
rescue => e | ||
logger.fatal e.message | ||
end | ||
default_task :lint | ||
|
||
private | ||
|
||
def logger | ||
return @logger if @logger | ||
@logger = Logger.new(STDOUT) | ||
if options[:quiet] | ||
@logger.level = Logger::FATAL | ||
elsif options[:debug] | ||
@logger.level = Logger::DEBUG | ||
elsif options[:verbose] | ||
@logger.level = Logger::INFO | ||
else | ||
@logger.level = Logger::INFO | ||
@logger.formatter = proc do |_severity, _datetime, _progname, msg| | ||
"#{msg}\n" | ||
end | ||
end | ||
@logger | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters