Skip to content

Instantly share code, notes, and snippets.

@jaderfeijo
Last active March 1, 2016 16:38
Show Gist options
  • Select an option

  • Save jaderfeijo/fc931878d93b699aa7a0 to your computer and use it in GitHub Desktop.

Select an option

Save jaderfeijo/fc931878d93b699aa7a0 to your computer and use it in GitHub Desktop.
version
#!/usr/bin/ruby
require 'plist'
command = ARGV[0]
file_path = "Info.plist"
supported_parameters = "Supported parameters: increment, decrement, print"
if !File.file?(file_path)
print "File '#{file_path}' not found.\n\n"
exit 1
end
if command == nil
print "Please specify a parameter.\n\n#{supported_parameters}\n\n"
exit 1
elsif command != "increment" && command != "decrement" && command != "print"
print "Invalid command '#{command}'\n\n#{supported_parameters}\n\n"
exit 1
end
plist = Plist::parse_xml(file_path)
version = plist['CFBundleShortVersionString']
version_arr = version.split('.')
major = version_arr[0].to_i
minor = version_arr[1].to_i
revision = version_arr[2].to_i
supported_version_segments = "Supported version segments: major, minor, revision (or rev)"
if command == "increment"
which_version = ARGV[1]
if which_version == "major"
major += 1
elsif which_version == "minor"
minor += 1
elsif which_version == "revision" || which_version == "rev"
revision += 1
else
print "Please specify a valid version segment to increment.\n\n#{supported_version_segments}\n\n"
exit 1
end
elsif command == "decrement"
which_version = ARGV[1]
if which_version == "major"
major -= 1
elsif which_version == "minor"
minor -= 1
elsif which_version == "revision" || which_version == "rev"
revision -= 1
else
print "Please specify a valid version segment to decrement.\n\n#{supported_version_segments}\n\n"
exit 1
end
end
version_string = "#{major.to_s}.#{minor.to_s}"
if revision > 0
version_string += ".#{revision.to_s}"
end
if command != "print"
plist['CFBundleShortVersionString'] = version_string
File.open(file_path, 'w') { |file| file.write(plist.to_plist) }
end
print version_string + "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment