Created
June 3, 2014 22:34
-
-
Save madson/cc28561ee6e9a1323f17 to your computer and use it in GitHub Desktop.
Script ruby to increment version number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
COMMANDS = ['major', 'minor', 'patch'] | |
regex = /^([0-9]+)\.?([0-9]*)\.?([0-9]*)/ | |
version = ARGV[0] | |
command = ARGV[1] | |
unless ARGV.size > 1 or version =~ regex | |
puts 'Usage: upgrade.rb <version> <command>' | |
puts | |
puts 'Commands:' | |
puts "\tmajor\tUpgrade major number" | |
puts "\tminor\tUpgrade minor number" | |
puts "\tpatch\tUpgrade patch number" | |
puts | |
puts 'Example:' | |
puts "\tupgrade.rb 1.3.5 minor" | |
exit 1 | |
end | |
parts = version.scan(regex) | |
parts = parts.first | |
parts.map! { |i| i.to_i } | |
major = parts[0] | |
minor = parts[1] | |
patch = parts[2] | |
if command == COMMANDS[0] | |
major += 1 | |
minor = 0 | |
patch = 0 | |
elsif command == COMMANDS[1] | |
minor += 1 | |
patch = 0 | |
else | |
patch += 1 | |
end | |
puts "#{major}.#{minor}.#{patch}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment