lib/bigfiles.rb in bigfiles-0.1.1 vs lib/bigfiles.rb in bigfiles-0.1.2

- old
+ new

@@ -1,25 +1,28 @@ require 'optparse' require_relative 'bigfiles/file_with_lines' require 'source_finder/source_file_globber' +require 'source_finder/option_parser' # Simple tool to find the largest source files in your project. module BigFiles # Simple tool to find the largest source files in your project. class BigFiles def initialize(args, io: Kernel, exiter: Kernel, file_with_lines: FileWithLines, source_file_globber: SourceFinder::SourceFileGlobber.new, - option_parser_class: OptionParser) + option_parser_class: OptionParser, + source_finder_option_parser: SourceFinder::OptionParser.new) @io = io @exiter = exiter @file_with_lines = file_with_lines @source_file_globber = source_file_globber @option_parser_class = option_parser_class + @source_finder_option_parser = source_finder_option_parser @options = parse_options(args) end def parse_options(args) options = nil @@ -28,47 +31,29 @@ @option_parser = opts end.parse!(args) options end - # XXX: Move to using SourceFinder for this - DEFAULT_GLOB = - '{app,lib,test,spec,feature}/**/*.{rb,swift,cpp,c,java,py}' - def glob - @options[:glob] || DEFAULT_GLOB + @options[:glob] || @source_finder_option_parser.default_source_files_glob end def exclude_glob - @options[:exclude] || '' + @options[:exclude] || + @source_finder_option_parser.default_source_files_exclude_glob end - def add_glob_option(opts, options) - opts.on('-g glob here', '--glob', - "Which files to parse - default is #{DEFAULT_GLOB}") do |v| - options[:glob] = v - end - end - - def add_exclude_glob_option(opts, options) - opts.on('-e glob here', '--exclude-glob', - 'Files to exclude - default is none') do |v| - options[:exclude] = v - end - end - def add_help_option(opts, options) opts.on('-h', '--help', 'This message') do |_| options[:help] = true end end def setup_options(opts) options = {} opts.banner = 'Usage: bigfiles [options]' - add_glob_option(opts, options) - add_exclude_glob_option(opts, options) + @source_finder_option_parser.add_options(opts, options) add_help_option(opts, options) options end def usage @@ -77,10 +62,10 @@ end def find_analyze_and_report_on_files @source_file_globber.source_files_glob = glob @source_file_globber.source_files_exclude_glob = exclude_glob - file_list = @source_file_globber.source_files + file_list = @source_file_globber.source_files_arr files_with_lines = file_list.map do |filename| @file_with_lines.new(filename) end files_with_lines.sort.reverse[0..2].each do |file| @io.puts "#{file.num_lines}: #{file.filename}"