class AlfonsoX::CLI
Command Line Interpreter tool for Alfonso X
Constants
- ERROR_EXIT_STATUS
Error exit status code
- SUCCESS_EXIT_STATUS
Success exit status code
Public Class Methods
new()
click to toggle source
Take the config file path
# File lib/alfonsox/cli.rb, line 16 def initialize @config_file_path = config_file_path end
Public Instance Methods
run()
click to toggle source
Run spell-check on files specified by config file
# 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
Private Instance Methods
config_file_path()
click to toggle source
Return the config file path @return [String] config file path that will be used when running Alfonso X tool.
# File lib/alfonsox/cli.rb, line 45 def config_file_path repo_config_file_path_yml = File.join(AlfonsoX::Utils.repo_root, AlfonsoX::CONFIG_FILE_NAME) return repo_config_file_path_yml if File.exist?(repo_config_file_path_yml) File.join(AlfonsoX::CONFIG_PATH, 'default.yml') end
print_error_status()
click to toggle source
Informs that something went wrong
# File lib/alfonsox/cli.rb, line 71 def print_error_status STDERR.puts '✗ Errors in code spellchecking' end
print_spellcheck_error(file_path, spellchecker_error)
click to toggle source
Shows a lone spellcheck error in the standard error output
# File lib/alfonsox/cli.rb, line 52 def print_spellcheck_error(file_path, spellchecker_error) STDERR.puts "#{file_path}:#{spellchecker_error.line} #{spellchecker_error.word}" end
print_status(exit_status)
click to toggle source
Print status of the spellcheck
# File lib/alfonsox/cli.rb, line 57 def print_status(exit_status) if exit_status == SUCCESS_EXIT_STATUS print_success_status elsif exit_status == ERROR_EXIT_STATUS print_error_status end end
print_success_status()
click to toggle source
Informs that everything went well
# File lib/alfonsox/cli.rb, line 66 def print_success_status STDOUT.puts '✔ Code is spell-checked correctly' end