lib/slim_lint/cli.rb in slim_lint-0.18.0 vs lib/slim_lint/cli.rb in slim_lint-0.19.0

- old
+ new

@@ -1,15 +1,22 @@ # frozen_string_literal: true require 'slim_lint' require 'slim_lint/options' -require 'sysexits' - module SlimLint # Command line application interface. class CLI # rubocop:disable Metrics/ClassLength + # Exit codes + # @see https://man.openbsd.org/sysexits.3 + EX_OK = 0 + EX_USAGE = 64 + EX_DATAERR = 65 + EX_NOINPUT = 67 + EX_SOFTWARE = 70 + EX_CONFIG = 78 + # Create a CLI that outputs to the specified logger. # # @param logger [SlimLint::Logger] def initialize(logger) @log = logger @@ -37,20 +44,20 @@ def act_on_options(options) log.color_enabled = options.fetch(:color, log.tty?) if options[:help] print_help(options) - Sysexits::EX_OK + EX_OK elsif options[:version] || options[:verbose_version] print_version(options) - Sysexits::EX_OK + EX_OK elsif options[:show_linters] print_available_linters - Sysexits::EX_OK + EX_OK elsif options[:show_reporters] print_available_reporters - Sysexits::EX_OK + EX_OK else scan_for_lints(options) end end @@ -58,33 +65,33 @@ # exception. def handle_exception(exception) case exception when SlimLint::Exceptions::ConfigurationError log.error exception.message - Sysexits::EX_CONFIG + EX_CONFIG when SlimLint::Exceptions::InvalidCLIOption log.error exception.message log.log "Run `#{APP_NAME}` --help for usage documentation" - Sysexits::EX_USAGE + EX_USAGE when SlimLint::Exceptions::InvalidFilePath log.error exception.message - Sysexits::EX_NOINPUT + EX_NOINPUT when SlimLint::Exceptions::NoLintersError log.error exception.message - Sysexits::EX_NOINPUT + EX_NOINPUT else print_unexpected_exception(exception) - Sysexits::EX_SOFTWARE + EX_SOFTWARE end end # Scans the files specified by the given options for lints. # # @return [Integer] exit status code def scan_for_lints(options) report = Runner.new.run(options) print_report(report, options) - report.failed? ? Sysexits::EX_DATAERR : Sysexits::EX_OK + report.failed? ? EX_DATAERR : EX_OK end # Outputs a report of the linter run using the specified reporter. def print_report(report, options) reporter = options.fetch(:reporter,