Class: Spellr::CLI
- Inherits:
-
Object
- Object
- Spellr::CLI
- Defined in:
- lib/spellr/cli.rb
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
Instance Method Summary collapse
- #check ⇒ Object
- #config_option(file) ⇒ Object
- #dry_run_option(_) ⇒ Object
- #files ⇒ Object
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
- #interactive_option(_) ⇒ Object
-
#options ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize.
- #options_help(_) ⇒ Object
- #parse_command ⇒ Object
- #parse_options ⇒ Object
- #quiet_option(_) ⇒ Object
- #validate_config ⇒ Object
- #version_option(_) ⇒ Object
- #wordlist_option(_) ⇒ Object
Constructor Details
#initialize(argv) ⇒ CLI
Returns a new instance of CLI.
13 14 15 16 17 |
# File 'lib/spellr/cli.rb', line 13 def initialize(argv) @argv = argv parse_command end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
11 12 13 |
# File 'lib/spellr/cli.rb', line 11 def argv @argv end |
Instance Method Details
#check ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/spellr/cli.rb', line 19 def check require_relative 'check' validate_config checker = Spellr::Check.new(files: files) checker.check exit checker.exit_code end |
#config_option(file) ⇒ Object
58 59 60 |
# File 'lib/spellr/cli.rb', line 58 def config_option(file) Spellr.config.config_file = Pathname.pwd.join(file). end |
#dry_run_option(_) ⇒ Object
62 63 64 65 66 |
# File 'lib/spellr/cli.rb', line 62 def dry_run_option(_) files.each { |f| puts f.relative_path_from(Pathname.pwd) } exit end |
#files ⇒ Object
37 38 39 40 |
# File 'lib/spellr/cli.rb', line 37 def files require_relative 'file_list' Spellr::FileList.new(*argv) end |
#interactive_option(_) ⇒ Object
53 54 55 56 |
# File 'lib/spellr/cli.rb', line 53 def interactive_option(_) require_relative 'interactive' Spellr.config.reporter = Spellr::Interactive.new end |
#options ⇒ Object
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/spellr/cli.rb', line 90 def # rubocop:disable Metrics/MethodLength, Metrics/AbcSize ||= begin opts = OptionParser.new opts. = '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('-d', '--dry-run', 'List files to be checked', &method(:dry_run_option)) opts.separator('') opts.on('-c', '--config FILENAME', String, " Path to the config file (default ./.spellr.yml)\n HELP\n opts.on('-v', '--version', 'Returns the current version', &method(:version_option))\n opts.on('-h', '--help', 'Shows this message', &method(:options_help))\n\n opts\n end\nend\n", &method(:config_option)) |
#options_help(_) ⇒ Object
80 81 82 83 84 |
# File 'lib/spellr/cli.rb', line 80 def (_) puts .help exit end |
#parse_command ⇒ Object
75 76 77 78 |
# File 'lib/spellr/cli.rb', line 75 def parse_command check end |
#parse_options ⇒ Object
86 87 88 |
# File 'lib/spellr/cli.rb', line 86 def .parse!(argv) end |
#quiet_option(_) ⇒ Object
47 48 49 50 51 |
# File 'lib/spellr/cli.rb', line 47 def quiet_option(_) Spellr.config.quiet = true require_relative 'quiet_reporter' Spellr.config.reporter = Spellr::QuietReporter.new end |
#validate_config ⇒ Object
30 31 32 33 34 35 |
# File 'lib/spellr/cli.rb', line 30 def validate_config return true if Spellr.config.valid? Spellr.config.print_errors exit 1 end |
#version_option(_) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/spellr/cli.rb', line 68 def version_option(_) require_relative 'version' puts(Spellr::VERSION) exit end |
#wordlist_option(_) ⇒ Object
42 43 44 45 |
# File 'lib/spellr/cli.rb', line 42 def wordlist_option(_) require_relative 'wordlist_reporter' Spellr.config.reporter = Spellr::WordlistReporter.new end |