Class: BigFiles::OptionParser
- Inherits:
-
Object
- Object
- BigFiles::OptionParser
- Defined in:
- lib/bigfiles/option_parser.rb
Overview
Parse options passed to bigfiles command
Instance Method Summary collapse
- #add_help_option(opts, options) ⇒ Object
- #add_num_files_option(opts, options) ⇒ Object
-
#initialize(option_parser_class: ::OptionParser, io: Kernel, exiter: Kernel, source_finder_option_parser:) ⇒ OptionParser
constructor
A new instance of OptionParser.
- #parse_options(args) ⇒ Object
- #setup_options(opts) ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize(option_parser_class: ::OptionParser, io: Kernel, exiter: Kernel, source_finder_option_parser:) ⇒ OptionParser
Returns a new instance of OptionParser.
8 9 10 11 12 13 14 15 16 |
# File 'lib/bigfiles/option_parser.rb', line 8 def initialize(option_parser_class: ::OptionParser, io: Kernel, exiter: Kernel, source_finder_option_parser:) @option_parser_class = option_parser_class @io = io @exiter = exiter @source_finder_option_parser = source_finder_option_parser end |
Instance Method Details
#add_help_option(opts, options) ⇒ Object
36 37 38 |
# File 'lib/bigfiles/option_parser.rb', line 36 def add_help_option(opts, ) opts.on('-h', '--help', 'This message') { |_| [:help] = true } end |
#add_num_files_option(opts, options) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/bigfiles/option_parser.rb', line 27 def add_num_files_option(opts, ) opts.on('-n', '--num-files number-here', Integer, "Top number of files to show--" \ "default #{Config::NUM_FILES_DEFAULT}") do |n| [:num_files] = n end end |
#parse_options(args) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/bigfiles/option_parser.rb', line 40 def (args) = nil @option_parser_class.new do |opts| = (opts) @option_parser = opts end.parse!(args) Config.new(**, source_finder_option_parser: @source_finder_option_parser) end |
#setup_options(opts) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/bigfiles/option_parser.rb', line 18 def (opts) = {} opts. = 'Usage: bigfiles [options]' @source_finder_option_parser.(opts, ) add_help_option(opts, ) add_num_files_option(opts, ) end |
#usage ⇒ Object
50 51 52 53 |
# File 'lib/bigfiles/option_parser.rb', line 50 def usage @io.puts @option_parser @exiter.exit(1) end |