class Pod::Command::Qpodfile
This is an example of a cocoapods plugin adding a top-level subcommand to the 'pod' command.
You can also create subcommands of existing or new commands. Say you wanted to add a subcommand to `list` to show newly deprecated pods, (e.g. `pod list deprecated`), there are a few things that would need to change.
-
move this file to `lib/pod/command/list/deprecated.rb` and update the class to exist in the the Pod::Command::List namespace
-
change this class to extend from `List` instead of `Command`. This tells the plugin system that it is a subcommand of `list`.
-
edit `lib/cocoapods_plugins.rb` to require this file
@todo Create a PR to add your plugin to CocoaPods/cocoapods.org
in the `plugins.json` file, once your plugin is released.
Public Class Methods
new(argv)
click to toggle source
Calls superclass method
# File lib/cocoapods-qpodfile/command/qpodfile.rb, line 32 def initialize(argv) @modules = argv.shift_argument super end
Public Instance Methods
run()
click to toggle source
# File lib/cocoapods-qpodfile/command/qpodfile.rb, line 42 def run verify_podfile_exists! podfile_path = Pathname.pwd + 'Podfile' podfile = Podfile.from_file(podfile_path) podfileYAML = podfile.to_yaml podfileHash = YAML.load(podfileYAML) configModule = @modules.split(",") hash = podfileHash["target_definitions"] contents ||= File.open(podfile_path, 'r:utf-8') { |f| f.read } podfile.target_definitions.each do |name, definition| if name != "Pods" && (@target == nil || @target == name) if name == "Qiyeyun" target_code = "target '#{name}' do\n\n" hash = podfileHash["target_definitions"] hash.each do |config| config["children"].each do |t| if name == t["name"] t["dependencies"].each do |depend| base_code = "" if depend.class == String if configModule.include?(depend) base_code = "pod '#{depend}'" if t.key?("configuration_pod_whitelist") buildConfigs1 = Array.new() if t["configuration_pod_whitelist"].key?("Debug") if t["configuration_pod_whitelist"]["Debug"].include?(depend) buildConfigs1 << "Debug" end end if t["configuration_pod_whitelist"].key?("Release") if t["configuration_pod_whitelist"]["Release"].include?(depend) buildConfigs1 << "Release" end end if !buildConfigs1.empty? base_code += ", :configurations => #{buildConfigs1.to_s}" end end base_code += "\n" end elsif depend.class == Hash if configModule.include?(depend.keys[0]) base_code = "pod '#{depend.keys[0]}'" depend.values[0].each do |value| if value.class == String base_code += ", '#{value}'" elsif value.class == Hash base_code += ", :#{value.keys[0]} => '#{value.values[0]}'" end end if t.key?("configuration_pod_whitelist") buildConfigs2 = Array.new() if t["configuration_pod_whitelist"].key?("Debug") if t["configuration_pod_whitelist"]["Debug"].include?(depend.keys[0]) buildConfigs2 << "Debug" end end if t["configuration_pod_whitelist"].key?("Release") if t["configuration_pod_whitelist"]["Release"].include?(depend.keys[0]) buildConfigs2 << "Release" end end if !buildConfigs2.empty? base_code += ", :configurations => #{buildConfigs2.to_s}" end end base_code += "\n" end end target_code += base_code end break end end end target_code += "\nend" contents = contents.gsub(/^target\s[\"|']#{name}[\"|'].+?end\n[\n]?/m, (target_code + "\n\n")) podfile_path.open('w') { |f| f << contents} elsif name == "Share" contents = contents.gsub(/^target\s[\"|']#{name}[\"|'].+?end\n[\n]?/m, ("" + "\n\n")) podfile_path.open('w') { |f| f << contents} end end end end
validate!()
click to toggle source
Calls superclass method
# File lib/cocoapods-qpodfile/command/qpodfile.rb, line 37 def validate! super help! 'modules is required.' unless @modules end