Class: WhyClasses::CLI

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

Overview

Command-line entry point. Parses ARGV into Options, runs, returns an exit code.

Constant Summary collapse

VALID_FORMATS =
%w[progress clang json diff].freeze
VALID_FAIL_LEVELS =
%w[none convention warning].freeze

Instance Method Summary collapse

Constructor Details

#initialize(argv, io: $stdout, err: $stderr) ⇒ CLI

Returns a new instance of CLI.



15
16
17
18
19
# File 'lib/why_classes/cli.rb', line 15

def initialize(argv, io: $stdout, err: $stderr)
  @argv = argv
  @io = io
  @err = err
end

Instance Method Details

#runObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/why_classes/cli.rb', line 21

def run
  overrides = parse_options
  return @early_exit if @early_exit

  options = Options.defaults(**overrides, paths: @argv)
  Runner.new(options).run(io: @io)
rescue OptionParser::ParseError => e
  @err.puts "why-classes: #{e.message}"
  2
rescue StandardError => e
  @err.puts "why-classes: #{e.class}: #{e.message}"
  2
end