Class: Pod::Command::Mexdup

Inherits:
Pod::Command show all
Defined in:
lib/cocoapods-mexdup/command/mexdup.rb

Overview

TODO:

Create a PR to add your plugin to CocoaPods/cocoapods.org in the `plugins.json` file, once your plugin is released.

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

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Mexdup

接收两个目录路径



32
33
34
35
36
# File 'lib/cocoapods-mexdup/command/mexdup.rb', line 32

def initialize(argv)
  @pod_folder = argv.shift_argument
  @shell_folder = argv.shift_argument
  super
end

Instance Method Details

#runObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cocoapods-mexdup/command/mexdup.rb', line 45

def run
  # FileUtils.rm_r 'Pods', :force => true
  # TOOD: 列举pod folder中的所有文件名

  pod_file_map = {}

  Find.find(@pod_folder) do |path|
    unless Dir.exist? path
      pod_file_map[(File.basename path)] = true
    end
  end

  Find.find(@shell_folder) do |path|
    unless Dir.exist? path
      file_name = File.basename(path)
      if pod_file_map[file_name] == true
        UI.puts "发现重复文件 #{file_name}"
        FileUtils.rm_f path
      end
    end
  end

end

#validate!Object

对目录进行校验



39
40
41
42
43
# File 'lib/cocoapods-mexdup/command/mexdup.rb', line 39

def validate!
  super
  help! 'pod folder is required.' unless @pod_folder
  help! 'shell folder is required.' unless @shell_folder
end