Class: Fastererer::CLI

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

Class Method Summary collapse

Class Method Details

.build_parser(options) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/fastererer/cli.rb', line 24

def self.build_parser(options)
  OptionParser.new do |opts|
    opts.banner = 'Usage: fastererer [options] [path]'
    opts.on('--no-color', 'Disable ANSI color in output') { options[:no_color] = true }
    opts.on('-h', '--help', 'Show this help') { show_help_and_exit(opts) }
    opts.on('-v', '--version', 'Show version') { show_version_and_exit }
  end
end

.executeObject



10
11
12
13
14
15
16
# File 'lib/fastererer/cli.rb', line 10

def self.execute
  options = parse_options(ARGV.dup)
  Painter.disable! if options[:no_color]
  file_traverser = Fastererer::FileTraverser.new(options[:path])
  file_traverser.traverse
  abort if file_traverser.offenses_found?
end

.parse_options(argv) ⇒ Object



18
19
20
21
22
# File 'lib/fastererer/cli.rb', line 18

def self.parse_options(argv)
  options = {}
  options[:path] = build_parser(options).parse(argv).first
  options
end

.show_help_and_exit(opts) ⇒ Object



33
34
35
36
# File 'lib/fastererer/cli.rb', line 33

def self.show_help_and_exit(opts)
  puts opts
  exit
end

.show_version_and_exitObject



38
39
40
41
# File 'lib/fastererer/cli.rb', line 38

def self.show_version_and_exit
  puts Fastererer::VERSION
  exit
end