Skip to content

Instantly share code, notes, and snippets.

@mgrebenets
Created June 8, 2015 12:04
Show Gist options
  • Save mgrebenets/041a0b61cd5e4aaa9bdd to your computer and use it in GitHub Desktop.
Save mgrebenets/041a0b61cd5e4aaa9bdd to your computer and use it in GitHub Desktop.
Share Xcode Schemes
#!/usr/bin/env ruby
# share_schemes.rb
require 'optparse'
require 'ostruct'
require 'rubygems'
require 'xcodeproj'
require 'colorize'
require 'fileutils'
# Option parser
class OptionParser
# Parse options
# @param [Array<String>] args command line args
# @return [OpenStruct] parsed options
def self.parse(args)
options = OpenStruct.new
options.project = nil
opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename($0)} [options]"
opts.separator("")
opts.on('-p [PROJECT]', '--project [PROJECT]', "Xcode project path. Automatically look up if not provided.") do |project|
options.project = project
end
opts.separator("")
opts.separator("Help:")
opts.on_tail('-h', '--help', 'Display this help') do
puts opts
exit
end
end
opt_parser.parse!(args)
options
end # parse()
end
options = OptionParser.parse(ARGV)
# Lookup for Xcode project other than Pods
# @return [String] name of Xcode project or nil if not found
def lookup_project
puts "Looking for Xcode project..."
# list all .xcodeproj files except Pods
projects_list = Dir.entries(".").select { |f| (f.end_with? ".xcodeproj") && (f != "Pods.xcodeproj") }
projects_list.empty? ? nil : projects_list.first
end
# lookup if not specificed
options.project = lookup_project if !options.project
if !options.project then
puts "Error".red.underline + ": No Xcode projects found in the working folder"
exit 1
end
puts "Using project path: " + "#{options.project}".green
xcproj = Xcodeproj::Project.open(options.project)
xcproj.recreate_user_schemes
xcproj.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment