#!/usr/bin/env ruby require 'travis_check_rubies/travis_yml' require 'optparse' require 'yaml' CONFIG_FILE = '.travis_check_rubies.yml' update = false options = if File.exist?(CONFIG_FILE) yaml = YAML.load_file(CONFIG_FILE) || {} fail "#{CONFIG_FILE} doesn't contain options hash" unless yaml.is_a?(Hash) yaml.map{ |key, value| [key.to_sym, value] }.to_h else {} end op = OptionParser.new op.banner += "\nOptions can be also specified in .travis_check_rubies.yml" op.on('--parts N|M..N', 'Match updates by how many parts (0..2 by default)') do |parts| options[:parts] = case parts when /\A\d+\z/ parts.to_i when /\A(\d+)..(\d+)\z/ $1.to_i..$2.to_i else fail "Expected number N or range M..N, got #{parts}" end end op.on('--[no-]allow-pre', 'Allow matching pre releases (false by default)') do |allow_pre| options[:allow_pre] = allow_pre end op.on('--[no-]intermediary', 'Include all latest version distinct by maximum matchable '\ 'parts, like 2.3.X when current is 2.2.X and latest is 2.4.X (true by default)') do |intermediary| options[:intermediary] = intermediary end op.on('--exclude V,V,V', Array, 'Exclude matching versions') do |exclude| options[:exclude] = exclude end op.on('--conservative', 'Update to first instead of last possible version') do options[:conservative] = true end op.on('-u', '--update', 'Update versions') do update = true end begin op.parse! rescue => e abort "#{e}\n\n#{op.help}" end travis_yml = TravisCheckRubies::TravisYml.new(options: options) if update abort unless travis_yml.update else abort unless travis_yml.suggest end