class VersionManager::CLI

Attributes

action_manager[R]
exec_name[R]

Public Class Methods

new(exec_name: __FILE__) click to toggle source
# File lib/version-manager/cli.rb, line 4
def initialize(exec_name: __FILE__)
  @exec_name = exec_name
  @action_manager = ActionManager.new(VersionManager.options)
end

Public Instance Methods

start() click to toggle source
# File lib/version-manager/cli.rb, line 9
    def start
      doc = <<~DOCOPT

      Usage:
        #{exec_name} make major
        #{exec_name} make minor
        #{exec_name} make patch
        #{exec_name} latest
        #{exec_name} -h | --help
        #{exec_name} -v | --version

      Options:
        -h --help     show this screen.
        -v --version  show version.
      DOCOPT

      begin
        parse_options(Docopt.docopt(doc))
      rescue StandardError => e
        puts e.message
      end
    end

Private Instance Methods

checkout_to_latest_version() click to toggle source
# File lib/version-manager/cli.rb, line 45
def checkout_to_latest_version
  return if action_manager.checkout_to_latest_version
  puts 'There are no any versions.'
end
confirm_new_version(new_version) click to toggle source
# File lib/version-manager/cli.rb, line 56
def confirm_new_version(new_version)
  Ask.confirm("You are going to upgrade version to #{new_version}. Do it?", default: false)
end
make_release(release_type) click to toggle source
# File lib/version-manager/cli.rb, line 50
def make_release(release_type)
  action_manager.release_new_version(release_type, method(:confirm_new_version), method(:retrieve_initial_version))
rescue VersionManager::VersionStorage::WrongLatestVersionError => e
  puts "There is inappropriate version #{e.version} in your local/remote repository. Please remove it"
end
parse_options(options) click to toggle source
# File lib/version-manager/cli.rb, line 36
def parse_options(options)
  puts VersionManager::VERSION if options['--version']
  checkout_to_latest_version if options['latest']
  %w(major minor patch).each do |release|
    next unless options[release]
    break make_release(release.to_sym)
  end
end
retrieve_initial_version() click to toggle source
# File lib/version-manager/cli.rb, line 60
def retrieve_initial_version
  puts 'There are no any versions. Please, input an initial one:'
  ReleaseVersion.new(STDIN.gets)
rescue ArgumentError => e
  puts e.message
  retry
end