module DistribBuilder module Versioner class ArgumentProcessor attr_accessor :show, :setup_version, :setup_build, :increment_build, :decrement_build, :verbose, :logger, :option_keys # nlevchuk: need to use logger here without passing it through argument to .new() def initialize(args, logger=nil) @args = args @option_keys = [] @logger = logger @show = nil @setup_version = nil @setup_build = nil @increment_build = false @decrement_build = false @verbose = false end def parse parser = OptionParser.new { |opts| opts.banner = 'Usage: distrib_builder version [options]' opts.on('-s', '--show [all|version|build]', String, [:all, :version, :build], 'Show current version and/or build') do |v| @show = v @option_keys << "show" end opts.on('--setup-version [VERSION]', String, 'Setup version VERSION in format: 1.2.3') do |v| @setup_version = v @option_keys << "setup-version" end opts.on('--setup-build [BUILD]', String, 'Setup build in format: 1') do |v| @setup_build = v @option_keys << "setup-build" end opts.on('-i', '--increment-build', 'Increment current build by 1') do @increment_build = true @option_keys << "increment-build" end opts.on('-d', '--decrement-build', 'Decrement current build by 1') do @decrement_build = true @option_keys << "decrement-build" end opts.on('--verbose', 'Output detail information about changed files') do @verbose = true @option_keys << "verbose" end opts.on('--help', 'Display нelp') { puts opts exit } } parser.parse!(@args.dup) end def validate_options if option_keys.include?("setup-build") && (setup_build.nil? || !/^\d+$/.match(setup_build)) logger.incorrect_setup_build(setup_build) end if option_keys.include?("setup-version") && (setup_version.nil? || !/^\d+\.\d+\.\d+$/.match(setup_version)) logger.incorrect_setup_version(setup_version) end end end end end