#!/usr/bin/env ruby # frozen_string_literal: true require 'pathname' require 'optparse' require 'objspace' require 'find' $LOAD_PATH.unshift File.expand_path('../lib', __dir__) require 'ruby_minimum_version' quiet = false verbose = false parser = OptionParser.new parser.banner.concat(' [filename ...]') parser.version = RubyMinimumVersion::VERSION parser.on('--quiet') { quiet = true } parser.on('--verbose') { verbose = true } parser.parse! quiet or $stderr.print 'Searching for Ruby files...' filenames = ARGV.flat_map do |file| File.file?(file) ? file : Find.find(file).select { |file| File.file?(file) && !file.end_with?('~') } end quiet or warn " found #{filenames.count} file(s)\n" filenames.each do |filename| filename = File.expand_path(filename) filename_in_log = Pathname(filename).relative_path_from(Dir.pwd) unless File.file?(filename) warn "No such file #{filename_in_log}" exit 1 end unless quiet if verbose warn "Scanning #{filename_in_log}..." else $stderr.print "Scanning #{filename_in_log}..." end end version = RubyMinimumVersion.new(filename, verbose: verbose).minimum_version unless quiet if verbose warn 'Scanning done' else warn ' done' end end if filenames.count >= 2 puts "#{filename_in_log}: #{version}" else puts version end end