Class: AlfonsoX::CLI

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

Overview

Command Line Interpreter tool for Alfonso X

Constant Summary collapse

SUCCESS_EXIT_STATUS =

Success exit status code

0
ERROR_EXIT_STATUS =

Error exit status code

1

Instance Method Summary collapse

Constructor Details

#initializeCLI

Take the config file path



16
17
18
# File 'lib/alfonsox/cli.rb', line 16

def initialize
  @config_file_path = config_file_path
end

Instance Method Details

#runObject

Run spell-check on files specified by config file



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/alfonsox/cli.rb', line 21

def run
  spellchecker = AlfonsoX::SpellChecker::Main.from_config(@config_file_path)
  spellchecker_errors_by_file = if ARGV&.length&.positive?
                                  spellchecker.check(ARGV)
                                else
                                  spellchecker.check_all
                                end

  exit_status = SUCCESS_EXIT_STATUS
  spellchecker_errors_by_file.each do |file_path, spellchecker_errors|
    spellchecker_errors.each do |spellchecker_error_i|
      print_spellcheck_error(file_path, spellchecker_error_i)
      exit_status = ERROR_EXIT_STATUS
    end
  end

  print_status(exit_status)
  exit(exit_status)
end