Forked from thelvis4/select_xcode_signing_method.rb
Last active
May 29, 2017 11:45
-
-
Save anivaros/8b1ccf69aacf5c707df21ef57eea8e70 to your computer and use it in GitHub Desktop.
This file contains hidden or 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/ruby | |
require 'xcodeproj' | |
# ============================================ | |
# !!! I've released a ruby gem that does the same thing, but better. | |
# You can install it by running `gem install xcprovisioner` or | |
# `sudo gem install xcprovisioner` if it asks for sudo rights. | |
# | |
# For more info: https://github.com/thelvis4/XCProvisioner | |
# ============================================ | |
# Usage: | |
# ruby select_xcode_signing_method.rb -p <path/to/xcode_project> -t <Target> -m ['Automatic' | 'Manual'] | |
class Options | |
attr_accessor :path, :target, :method | |
def initialize(args) | |
@path = args[:path] || Dir.glob("*.xcodeproj").first | |
@target = args[:target] | |
@method = args[:method] | |
end | |
end | |
def parse_args | |
options_hash = {} | |
args = ARGV | |
args.each_with_index do |arg, index| | |
case arg | |
when '--project_path', '-p' | |
path = args[index + 1] | |
unless File.exist?(path) | |
abort('There is no file at specified path.') | |
end | |
options_hash[:path] = path | |
when '--target', '-t' | |
options_hash[:target] = args[index + 1] | |
when '--signing_method', '-m' | |
method = args[index + 1] | |
unless ['Automatic', 'Manual'].include?(method) | |
abort("'Invalid signing method specified. Please use either 'Automatic' or 'Manual'") | |
end | |
options_hash[:method] = method | |
end | |
end | |
options_hash | |
end | |
options = Options.new parse_args | |
project = Xcodeproj::Project.open(options.path) | |
target_with_name = project.targets.select {|target| target.name == options.target }.first | |
unless !target_with_name | |
target_id = target_with_name.uuid | |
attributes = project.root_object.attributes['TargetAttributes'] | |
target_attributes = attributes[target_id] | |
target_attributes['ProvisioningStyle'] = options.method | |
project.save | |
puts "Code signing was set to '#{options.method}'." | |
else | |
puts "Target with name '#{options.target}' not found." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment