class BigFiles::OptionParser
Parse options passed to bigfiles command
Public Class Methods
new(option_parser_class: ::OptionParser, io: Kernel, exiter: Kernel, source_finder_option_parser:)
click to toggle source
# 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
Public Instance Methods
add_help_option(opts, options)
click to toggle source
# File lib/bigfiles/option_parser.rb, line 36 def add_help_option(opts, options) opts.on('-h', '--help', 'This message') { |_| options[:help] = true } end
add_num_files_option(opts, options)
click to toggle source
# File lib/bigfiles/option_parser.rb, line 27 def add_num_files_option(opts, options) opts.on('-n', '--num-files number-here', Integer, "Top number of files to show--" \ "default #{Config::NUM_FILES_DEFAULT}") do |n| options[:num_files] = n end end
parse_options(args)
click to toggle source
# File lib/bigfiles/option_parser.rb, line 40 def parse_options(args) options = nil @option_parser_class.new do |opts| options = setup_options(opts) @option_parser = opts end.parse!(args) Config.new(**options, source_finder_option_parser: @source_finder_option_parser) end
setup_options(opts)
click to toggle source
# File lib/bigfiles/option_parser.rb, line 18 def setup_options(opts) options = {} opts.banner = 'Usage: bigfiles [options]' @source_finder_option_parser.add_options(opts, options) add_help_option(opts, options) add_num_files_option(opts, options) options end
usage()
click to toggle source
# File lib/bigfiles/option_parser.rb, line 50 def usage @io.puts @option_parser @exiter.exit(1) end