#!/usr/bin/env ruby $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require 'optparse' require 'tagging/app_version' module Tagging class CLI def self.run(options) app_version = Tagging::AppVersion.new(options) if options[:push] puts app_version.increment_and_push exit 0 elsif options[:version] puts app_version.version exit 0 elsif options[:next_version] puts app_version.increment_version exit 0 elsif options[:load_tags] puts app_version.load_tags exit 0 else puts "## [message] Run `tagging --help' for more options." end end def self.options_verify?(op) if op[:help] and ([op[:push], op[:version], op[:next_version]].compact.length > 1) warn("[fail] Can only push, version or next_version. Choose one.") exit(1) end end end end options = {} if ARGV.first == 'push' options[:push] = true opt_parser = OptionParser.new do |opt| opt.banner = "Usage: git-tagging push [OPTIONS]" opt.separator "" opt.separator "Options" # git config --global opt.on("--config [variables]", "user.email \"you@example.com\" and user.name \"Name\". Like `git config --global`", String) do |value| options[:config] = Hash[*ARGV] end opt.on("-m", "Tag message", String) do |message| options[:message] = message end opt.on_tail("-h","--help","help push command") do puts opt_parser exit end end else opt_parser = OptionParser.new do |opt| opt.banner = "Usage: git-tagging [OPTIONS]" opt.separator "" opt.separator "Options" # opt.on("-p","--push","Increment version and push to tag") do |value| # options[:push] = value # end opt.on("-v","--version","Show current version into rails app path") do |value| options[:version] = value end opt.on("-n","--next-version","Show the next version") do |value| options[:next_version] = value end opt.on("-f","--fetch-tags","Load remote tags") do options[:load_tags] = true end opt.on_tail("-h","--help","help") do puts opt_parser exit end end end opt_parser.parse! Tagging::CLI.run(options)