Last active
November 30, 2015 22:34
-
-
Save Noreaster76/27046af0fa3c6223ffaf 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
require 'Slop' | |
require 'Xcodeproj' | |
DEFAULT_PROJECT_FILE = 'Foo/Bar.xcodeproj' | |
opts = Slop.parse do |o| | |
o.string '-t', '--target', 'the name of the test target from which you want to remove all other spec files' | |
o.array '-k', '--keep', 'either a single file, or a comma-separated list of files that you want to keep in the test target; all other files matching /Spec.m$/ will be removed; note that you can submit --keep a.m --keep b.m, if you don\'t want to use a comma-separated list', delimiter: ',' | |
o.string '-p', '--project', "the project file containing the test target you want to modify; default is #{DEFAULT_PROJECT_FILE}", default: DEFAULT_PROJECT_FILE | |
o.on '-h', '--help', 'print this help message' do | |
puts o | |
exit | |
end | |
end | |
project_path = opts[:project] | |
test_target = opts[:target] | |
test_files_to_keep = opts[:keep] | |
project = Xcodeproj::Project.open(project_path) | |
kif_tests_1 = project.targets.find { |target| target.name == test_target } | |
compile_sources_build_phase = kif_tests_1.build_phases.find { |phase| phase.is_a? Xcodeproj::Project::Object::PBXSourcesBuildPhase } | |
build_files_to_remove = compile_sources_build_phase.files.select do |build_file| | |
build_file.display_name.end_with?('Spec.m') && !test_files_to_keep.include?(build_file.display_name) | |
end | |
build_files_to_remove.each { |build_file| compile_sources_build_phase.remove_build_file build_file } | |
project.save |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires the Xcodeproj gem to be installed.