require 'distrib_builder/versioner/argument_processor' require 'distrib_builder/versioner/file_processor' require 'distrib_builder/versioner/version_processor' require 'distrib_builder/versioner/logger' module DistribBuilder module Versioner class Main attr_accessor :arg_processor, :file_processor, :version_processor, :logger def initialize(args) @args = args @arg_processor = nil @file_processor = nil @version_processor = nil @logger = nil end def run prepare_processors if arg_processor.show; show elsif arg_processor.increment_build; increment_build elsif arg_processor.decrement_build; decrement_build elsif arg_processor.setup_build; setup_build elsif arg_processor.setup_version; setup_version end end def increment_build logger.start_increment_build version_processor.build_up! logger.new_version(version_processor.full_version) file_processor.replace_version_and_build_in_files(version_processor.versions_hash) logger.build_changed(version_processor.build) end def decrement_build logger.start_decrement_build version_processor.build_down! logger.new_version(version_processor.full_version) file_processor.replace_version_and_build_in_files(version_processor.versions_hash) logger.build_changed(version_processor.build) end def setup_build logger.start_setup_build version_processor.setup_build!(arg_processor.setup_build) logger.new_version(version_processor.full_version) file_processor.replace_version_and_build_in_files(version_processor.versions_hash) logger.build_changed(version_processor.build) end def setup_version logger.start_setup_version version_processor.setup_version!(arg_processor.setup_version) logger.new_version(version_processor.full_version) file_processor.replace_version_and_build_in_files(version_processor.versions_hash) logger.version_changed(version_processor.only_version) end def show case arg_processor.show when :version logger.show_current_version(version_processor.only_version) when :build logger.show_current_build(version_processor.build) else logger.show_current_version(version_processor.only_version) logger.show_current_build(version_processor.build) end end private def prepare_processors @logger = Logger.new @arg_processor = ArgumentProcessor.new(@args, logger) @arg_processor.parse @logger.verbose = arg_processor.verbose # nlevchuk: need to fix later @arg_processor.validate_options @file_processor = FileProcessor.new(logger) @file_processor.read_config_files @version_processor = VersionProcessor.new(file_processor.read_version_and_build) end end end end