class Forspell::CLI
Constants
- CONFIG_PATH
- DEFAULT_CUSTOM_DICT
- DEFINITIONS
- ERROR_CODE
- FORMATS
- FORMAT_ERR
Public Class Methods
new(options)
click to toggle source
# File lib/forspell/cli.rb, line 35 def initialize options @options = options end
Public Instance Methods
call()
click to toggle source
# File lib/forspell/cli.rb, line 39 def call init_options init_reporter create_files_list init_speller run end
Private Instance Methods
create_files_list()
click to toggle source
# File lib/forspell/cli.rb, line 49 def create_files_list @files = FileList.new(paths: @opts.arguments, exclude_paths: @opts[:exclude_paths]) rescue Forspell::FileList::PathLoadError => path @reporter.path_load_error path exit ERROR_CODE end
init_options()
click to toggle source
# File lib/forspell/cli.rb, line 56 def init_options @options += File.read(CONFIG_PATH).tr("\n", ' ').split(' ') if File.exist?(CONFIG_PATH) @opts = Slop.parse(@options, &DEFINITIONS) @opts.arguments << '.' if @opts.arguments.empty? @opts[:format] = 'dictionary' if @opts[:gen_dictionary] @opts[:format] = @opts[:format]&.downcase end
init_reporter()
click to toggle source
# File lib/forspell/cli.rb, line 82 def init_reporter @reporter = Reporter.new(**@opts.to_hash.slice(:logfile, :format, :verbose, :print_filepaths)) end
init_speller()
click to toggle source
# File lib/forspell/cli.rb, line 67 def init_speller @opts[:custom_paths].each do |path| next if File.exist?(path) puts "Custom dictionary not found: #{path}" exit(ERROR_CODE) end @opts[:custom_paths] << DEFAULT_CUSTOM_DICT if File.exist?(DEFAULT_CUSTOM_DICT) suggestions_size = (@opts[:gen_dictionary] || @opts[:no_suggest]) ? 0 : @opts[:suggestions_size] suggestions_size ||= 0 @speller = Speller.new(@opts[:dictionary_path], *@opts[:custom_paths], suggestions_size: suggestions_size) end
run()
click to toggle source
# File lib/forspell/cli.rb, line 86 def run runner = Forspell::Runner.new(files: @files, speller: @speller, reporter: @reporter) runner.call exit @reporter.finalize end