Class: LintTrappings::ArgumentsParser
- Inherits:
-
Object
- Object
- LintTrappings::ArgumentsParser
- Defined in:
- lib/lint_trappings/arguments_parser.rb
Overview
Handles option parsing for the command line application.
Instance Method Summary collapse
-
#initialize(application) ⇒ ArgumentsParser
constructor
A new instance of ArgumentsParser.
-
#parse(args) ⇒ Hash
Parses command line options into an options hash.
Constructor Details
#initialize(application) ⇒ ArgumentsParser
Returns a new instance of ArgumentsParser.
6 7 8 |
# File 'lib/lint_trappings/arguments_parser.rb', line 6 def initialize(application) @application = application end |
Instance Method Details
#parse(args) ⇒ Hash
Parses command line options into an options hash.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/lint_trappings/arguments_parser.rb', line 15 def parse(args) = {} [:command] = :scan # Default command is to scan for lints OptionParser.new do |parser| parser. = "Usage: #{@application.executable_name} [options] [file1, file2, ...]" parser parser parser parser end.parse!(args) # Any remaining arguments are assumed to be files that should be linted [:included_paths] = args rescue OptionParser::InvalidOption => ex raise InvalidCliOptionError, "#{ex.message}\nRun `#{@application.executable_name} --help` to " \ 'see a list of available options.' end |