class Bunup::CLI
Parse args, run services, handle output, and handle exits
Constants
- COMMITING_MSG
- E_DIRTY_GEMFILE
- GIT_REF_UPDATE_WARNING
- MAJOR_VERSION_UPDATE_WARNING_FMT
- UPDATING_MSG_FMT
Public Class Methods
new(args)
click to toggle source
# File lib/bunup/cli.rb, line 19 def initialize(args) @options = ::Bunup::Options.parse!(args) @args = args @exit_status = true end
Public Instance Methods
run()
click to toggle source
# File lib/bunup/cli.rb, line 25 def run abort(E_DIRTY_GEMFILE) unless ::Bunup::Services::Commiter.clean_gemfile? @gems = build_gems update_and_commit_changes exit @exit_status end
Private Instance Methods
build_gem(match_data)
click to toggle source
# File lib/bunup/cli.rb, line 34 def build_gem(match_data) ::Bunup::Gem.new( name: match_data[:name], installed_version: match_data[:installed], newest_version: match_data[:newest] ) end
build_gems()
click to toggle source
# File lib/bunup/cli.rb, line 42 def build_gems bundle_outdated.split("\n").map.with_object([]) do |line, gems| next unless Bundler::OUTDATED_PATTERN =~ line match_data = Bundler::OUTDATED_PATTERN.match(line) gems << build_gem(match_data) end end
bundle_outdated()
click to toggle source
# File lib/bunup/cli.rb, line 51 def bundle_outdated puts 'Checking for updates' Bundler.outdated(bunup_all? ? [] : @args) rescue ::SystemExit => e handle_system_exit(e) '' end
bunup_all?()
click to toggle source
# File lib/bunup/cli.rb, line 59 def bunup_all? @options.all end
bunup_many?()
click to toggle source
# File lib/bunup/cli.rb, line 63 def bunup_many? @args.count > 1 || bunup_all? end
commit()
click to toggle source
# File lib/bunup/cli.rb, line 67 def commit Services::Commiter.new(@gem).perform end
handle_system_exit(exception)
click to toggle source
# File lib/bunup/cli.rb, line 71 def handle_system_exit(exception) @exit_status = exception.success? msg = [] msg << 'ERROR:' unless exception.success? msg << exception.message puts msg.join(' ') + "\n" raise exception unless bunup_many? end
major_version_update?()
click to toggle source
# File lib/bunup/cli.rb, line 80 def major_version_update? return false if @gem.newest_version.nil? || @gem.installed_version.nil? @gem.newest_version.major > @gem.installed_version.major end
prompt_for_git_ref_update()
click to toggle source
A major version update has breaking changes, according to Semantic Versioning (semver.org/spec/v2.0.0.html). Let's make sure the user is aware of that.
# File lib/bunup/cli.rb, line 89 def prompt_for_git_ref_update print format( GIT_REF_UPDATE_WARNING, gem_name: @gem.name, installed_version: @gem.installed_version, newest_version: @gem.newest_version ) if @options[:assume_yes_for_git_update] print "assuming yes\n" else unless STDIN.gets.chomp.casecmp('y').zero? raise ::SystemExit.new(true, 'No update performed') end end end
prompt_for_major_update()
click to toggle source
A major version update has breaking changes, according to Semantic Versioning (semver.org/spec/v2.0.0.html). Let's make sure the user is aware of that.
# File lib/bunup/cli.rb, line 108 def prompt_for_major_update print format( MAJOR_VERSION_UPDATE_WARNING_FMT, gem_name: @gem.name, installed_version: @gem.installed_version, newest_version: @gem.newest_version ) if @options[:assume_yes_for_major_version_update] print "assuming yes\n" else unless STDIN.gets.chomp.casecmp('y').zero? raise ::SystemExit.new(true, 'No update performed') end end end
update()
click to toggle source
# File lib/bunup/cli.rb, line 124 def update puts format( UPDATING_MSG_FMT, remaining: "#{@gems.find_index(@gem) + 1}/#{@gems.count}", gem_name: @gem.name, installed_version: @gem.installed_version, newest_version: @gem.newest_version ) Services::Updater.new(@gem).perform end
update_and_commit_changes()
click to toggle source
# File lib/bunup/cli.rb, line 135 def update_and_commit_changes @gems.each do |gem| @gem = gem begin prompt_for_major_update if major_version_update? prompt_for_git_ref_update if @gem.installed_from_git? update commit rescue ::SystemExit => e handle_system_exit(e) next end end end