class Spellr::CLI::Options

Public Class Methods

parse(argv) click to toggle source
# File lib/spellr/cli_options.rb, line 11
def parse(argv)
  @parallel_option = false

  options.parse!(argv)
end

Private Class Methods

config_option(file) click to toggle source
# File lib/spellr/cli_options.rb, line 66
def config_option(file)
  file = Spellr.pwd.join(file).expand_path

  unless ::File.readable?(file)
    raise Spellr::Config::NotFound, "Config error: #{file} not found or not readable"
  end

  Spellr.config.config_file = file
end
dry_run_option(_) click to toggle source
# File lib/spellr/cli_options.rb, line 87
def dry_run_option(_)
  Spellr.config.dry_run = true
end
interactive_option(_) click to toggle source
# File lib/spellr/cli_options.rb, line 55
def interactive_option(_)
  require_relative 'interactive'
  require_relative 'check_interactive'
  Spellr.config.reporter = Spellr::Interactive.new
  Spellr.config.checker = Spellr::CheckInteractive unless @parallel_option
end
options() click to toggle source

rubocop:disable Layout/LineLength

# File lib/spellr/cli_options.rb, line 20
        def options # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
          opts = OptionParser.new

          opts.banner = 'Usage: spellr [options] [files]'
          opts.separator('')
          opts.on('-w', '--wordlist', 'Outputs errors in wordlist format', &method(:wordlist_option))
          opts.on('-q', '--quiet', 'Silences output', &method(:quiet_option))
          opts.on('-i', '--interactive', 'Runs the spell check interactively', &method(:interactive_option))
          opts.separator('')
          opts.on('--[no-]parallel', 'Run in parallel or not, default --parallel', &method(:parallel_option))
          opts.on('-d', '--dry-run', 'List files to be checked', &method(:dry_run_option))
          opts.on('-f', '--suppress-file-rules', <<~HELP, &method(:suppress_file_rules))
            Suppress all configured, default, and gitignore include and exclude patterns
          HELP
          opts.separator('')
          opts.on('-c', '--config FILENAME', String, <<~HELP, &method(:config_option))
            Path to the config file (default ./.spellr.yml)
          HELP
          opts.on('-v', '--version', 'Returns the current version', &method(:version_option))
          opts.on('-h', '--help', 'Shows this message', &method(:options_help))

          opts
        end
options_help(_) click to toggle source
# File lib/spellr/cli_options.rb, line 98
def options_help(_)
  Spellr.config.output.puts options.help

  Spellr.exit
end
parallel_option(parallel) click to toggle source
# File lib/spellr/cli_options.rb, line 76
def parallel_option(parallel) # rubocop:disable Metrics/MethodLength
  @parallel_option = true
  Spellr.config.checker = if parallel
    require_relative 'check_parallel'
    Spellr::CheckParallel
  else
    require_relative 'check'
    Spellr::Check
  end
end
quiet_option(_) click to toggle source
# File lib/spellr/cli_options.rb, line 50
def quiet_option(_)
  require_relative 'quiet_reporter'
  Spellr.config.reporter = Spellr::QuietReporter.new
end
suppress_file_rules(_) click to toggle source
# File lib/spellr/cli_options.rb, line 62
def suppress_file_rules(_)
  Spellr.config.suppress_file_rules = true
end
version_option(_) click to toggle source
# File lib/spellr/cli_options.rb, line 91
def version_option(_)
  require_relative 'version'
  Spellr.config.output.puts(Spellr::VERSION)

  Spellr.exit
end
wordlist_option(_) click to toggle source

rubocop:enable Layout/LineLength

# File lib/spellr/cli_options.rb, line 45
def wordlist_option(_)
  require_relative 'wordlist_reporter'
  Spellr.config.reporter = Spellr::WordlistReporter.new
end