class Pod::Command::Templates

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.

@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-templates/command/templates.rb, line 33
def initialize(argv)
  @url = argv.shift_argument
  @name = File.basename @url.split("/").last
  @owner = @url.split("/")[-2]
  super
end

Public Instance Methods

run() click to toggle source
# File lib/cocoapods-templates/command/templates.rb, line 47
def run
  UI.puts "Add your implementation for the cocoapods-templates plugin in #{__FILE__}"

  tmp_directory = Dir.mktmpdir
  Dir.chdir(tmp_directory) do
    UI.puts "Cloning #{@url}"
    Git.clone @url, @name

    templates = Dir["**/*.xctemplate"]

    if templates.count == 0
      UI.puts "#{@url} does not contain any Xcode templates"
    else
      UI.puts "Installing #{templates.count} template(s) to ~/Library/Developer/Xcode/Templates/File Template for #{@owner}"
      base = File.absolute_path "#{ENV["HOME"]}/Library/Developer/Xcode/Templates/File Template"

      FileUtils.mkdir_p base
      FileUtils.rm_rf "#{base}/#{@owner}"
      FileUtils.mkdir_p "#{base}/#{@owner}"

      templates.each do |path|
        FileUtils.cp_r path, "#{base}/#{@owner}"
      end

      UI.puts "Please restart Xcode for the changes to take affect"
    end
  end
end
validate!() click to toggle source
Calls superclass method
# File lib/cocoapods-templates/command/templates.rb, line 40
def validate!
  super
  help! 'An URL is required' unless @url
  help! 'URL is invalid, expected something like https://example.com/repo.git' unless @url.start_with? "https://"
  help! 'URL is invalid, expected something like https://example.com/repo.git' unless @url.end_with? ".git"
end