class Bump::Application
The application
Public Class Methods
@param [Hash] options The cli options @param [String] help The help message @param [String] version The version expression of this command @param [String] file The file name of bump info file @param [Bump::Logger] logger The logger @param [Bump::Command] logger The command executer
# File lib/bump/application.rb, line 12 def initialize(options, help, version, file, logger, command = nil) @options = options @help = help @version = version @file = file @logger = logger @command = command @command = Bump::Command.new @logger if @command.nil? end
Public Instance Methods
The bump action @return [Boolean] true iff success
# File lib/bump/application.rb, line 158 def action_bump bump_info = create_bump_info return false if bump_info.nil? print_bump_plan bump_info unless bump_info.valid? print_invalid_bump_info bump_info return false end bump_info.perform_update report bump_info save_bump_info bump_info commit_and_tag bump_info if @options[:commit] true end
handler of ‘bmp –help`
@return [void]
# File lib/bump/application.rb, line 55 def action_help log @help true end
handler of ‘bmp [–info]`
@return [void]
# File lib/bump/application.rb, line 124 def action_info bump_info = create_bump_info return false if bump_info.nil? print_version_patterns bump_info bump_info.valid? end
handler of ‘bmp –version`
@return [void]
# File lib/bump/application.rb, line 46 def action_version log @version true end
Gets the requested bump level. @return [Symbol]
# File lib/bump/application.rb, line 184 def bump_level return :major if @options[:major] return :minor if @options[:minor] return :patch if @options[:patch] end
Returns true iff it’s a bump option. @param [Hash] options The options
# File lib/bump/application.rb, line 39 def bump_option?(options) options[:major] || options[:minor] || options[:patch] || options[:commit] || options[:preid] || options[:release] end
Commits current changes and tag it by the current version. @param [Bump::BumpInfo] bump_info The bump info
# File lib/bump/application.rb, line 241 def commit_and_tag(bump_info) @logger.log '===> executing commands' @command.exec 'git add .' @command.exec "git commit -m '#{bump_info.commit_message}'" @command.exec "git tag v#{bump_info.after_version}" end
Gets the bump info @private @return [Bump::BumpInfo]
# File lib/bump/application.rb, line 64 def create_bump_info repo = BumpInfoRepository.new @file begin bump_info = repo.from_file rescue Errno::ENOENT log_red "Error: the file `#{@file}` not found." return nil end bump_info end
Logs the message
@param [String] message @param [Boolean] newline @return [void]
# File lib/bump/application.rb, line 269 def log(message = '', newline = true) @logger.log message, newline end
Logs the message in green
@param [String] message @param [Boolean] newline @return [void]
# File lib/bump/application.rb, line 287 def log_green(message, newline = true) log @logger.green(message), newline end
Logs the message in red
@param [String] message @param [Boolean] newline @return [void]
# File lib/bump/application.rb, line 278 def log_red(message, newline = true) log @logger.red(message), newline end
The entry point
@return [void]
# File lib/bump/application.rb, line 251 def main case select_action when :version action_version when :help action_help when :info action_info when :bump action_bump end end
Prints the version bump plan. @param [Bump::BumpInfo] bump_info The bump info
# File lib/bump/application.rb, line 192 def print_bump_plan(bump_info) level = bump_level print_bump_plan_level level, bump_info unless level.nil? preid = @options[:preid] print_bump_plan_preid preid, bump_info unless preid.nil? print_bump_plan_release bump_info if @options[:release] log end
Prints the bump plan for the given level. @param [Symbol] level The level @param [Bump::BumpInfo] bump_info The bump info
# File lib/bump/application.rb, line 207 def print_bump_plan_level(level, bump_info) bump_info.bump level log "Bump #{level} level" print_version_transition bump_info end
Prints the bump plan for the give preid. @param [Bump::BumpInfo] bump_info The bump info
# File lib/bump/application.rb, line 216 def print_bump_plan_preid(preid, bump_info) bump_info.preid = preid log 'Set pre-release version id: ', false log_green preid print_version_transition bump_info end
Prints the bump plan for the release @param [Bump::BumpInfo] bump_info The bump info
# File lib/bump/application.rb, line 226 def print_bump_plan_release(bump_info) bump_info.preid = nil log 'Remove pre-release version id' print_version_transition bump_info end
Checks the bumping is possible. @param [Bump::BumpInfo] bumpInfo @return [void]
# File lib/bump/application.rb, line 137 def print_invalid_bump_info(bump_info) log_red 'Some patterns are invalid!' log_red 'Stops updating version numbers.' log print_version_patterns bump_info end
Prints the pattern info for the given rule @param [Bump::FileUpdateRule] rule The rule
# File lib/bump/application.rb, line 102 def print_rule(rule) unless rule.file_exists log_red " #{rule.file}:", false log_red " '#{rule.before_pattern}' (file not found)" return end log " #{rule.file}:", false unless rule.pattern_exists log_red " '#{rule.before_pattern}' (pattern not found)" return end log_green " '#{rule.before_pattern}'" end
Shows the version patterns. @param [Bump::BumpInfo] bumpInfo @return [void]
# File lib/bump/application.rb, line 89 def print_version_patterns(bump_info) log 'Current Version:', false log_green " #{bump_info.before_version}" log 'Version patterns:' bump_info.update_rules.each do |rule| print_rule rule end end
Prints the version transition. @param [Bump::BumpInfo] bump_info The bump info
# File lib/bump/application.rb, line 235 def print_version_transition(bump_info) log_green " #{bump_info.before_version} => #{bump_info.after_version}" end
Reports the bumping details. @param [Bump::BumpInfo] bumpInfo
# File lib/bump/application.rb, line 147 def report(bump_info) bump_info.update_rules.each do |rule| log rule.file.to_s log ' Performed pattern replacement:' log_green " '#{rule.before_pattern}' => '#{rule.after_pattern}'" log end end
Saves the bump info @param [Bump::BumpInfo] bumpInfo @return [void]
# File lib/bump/application.rb, line 80 def save_bump_info(bump_info) repo = BumpInfoRepository.new @file repo.save bump_info end
Returns a symbol which represents the action to perform. @return [Symbol]
# File lib/bump/application.rb, line 24 def select_action return :help if @options[:help] return :version if @options[:version] return :info if @options[:info] return :bump if bump_option? @options # command without options invokes info action :info end