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/801eb09e6ee38c143f52 to your computer and use it in GitHub Desktop.

Select an option

Save jaderfeijo/801eb09e6ee38c143f52 to your computer and use it in GitHub Desktop.
build
#!/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)
bundle_version = plist['CFBundleVersion'].to_i
if command == "increment"
bundle_version += 1
elsif command == "decrement"
bundle_version -= 1
end
if command != "print"
plist['CFBundleVersion'] = bundle_version.to_s
File.open(file_path, 'w') { |file| file.write(plist.to_plist) }
end
print bundle_version.to_s + "\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment