Class: PPL::Command

Inherits:
CLAide::Command
  • Object
show all
Defined in:
lib/pod-pipeline/command.rb,
lib/pod-pipeline/command/new.rb,
lib/pod-pipeline/command/scan.rb,
lib/pod-pipeline/command/build.rb,
lib/pod-pipeline/command/update.rb,
lib/pod-pipeline/command/publish.rb,
lib/pod-pipeline/command/scan/all.rb,
lib/pod-pipeline/command/scan/name.rb,
lib/pod-pipeline/command/scan/branch.rb,
lib/pod-pipeline/command/scan/depend.rb,
lib/pod-pipeline/command/scan/remote.rb,
lib/pod-pipeline/command/scan/version.rb,
lib/pod-pipeline/command/scan/workspace.rb

Direct Known Subclasses

Build, New, Publish, Scan, Update

Defined Under Namespace

Classes: Build, New, Publish, Scan, Update

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Command

Returns a new instance of Command.



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/pod-pipeline/command.rb', line 92

def initialize(argv)
    @argv_extension = Hash.new
    self.class.options_extension_hash.each_key { |key|
        @argv_extension[key] = Array.new
        self.class.options.each do |option|
            name = option.first
            if name.include?(key)
                is_option = name.include? '='
                if is_option
                    option = name.gsub(/(--)(.*)(=.*)/,"\\2")
                    value = argv.option(option, '')
                    @argv_extension[key] << name.gsub(/(--.*=)(.*)/,"\\1#{value}").gsub("#{key}-",'') unless value.empty?
                else
                    flag = name.gsub(/(--)(.*)/,'\\2')
                    value = argv.flag?(flag)
                    @argv_extension[key] << name.gsub("#{key}-",'') if value
                end
            end
        end
    }

    super
end

Class Method Details

.ensure_not_root_or_allowed!(argv, uid = Process.uid, is_windows = Gem.win_platform?) ⇒ void

This method returns an undefined value.

确保root用户



50
51
52
53
# File 'lib/pod-pipeline/command.rb', line 50

def self.ensure_not_root_or_allowed!(argv, uid = Process.uid, is_windows = Gem.win_platform?)
    root_allowed = argv.include?('--allow-root') || !ENV['COCOAPODS_ALLOW_ROOT'].nil?
    help! 'You cannot run Pod-Pipeline as root.' unless root_allowed || uid != 0 || is_windows
end

.git_versionGem::Version

读取Git版本号,返回一个新的 Gem::Version 实例

Returns:

  • (Gem::Version)


59
60
61
62
63
64
65
# File 'lib/pod-pipeline/command.rb', line 59

def self.git_version
    raw_version = `git version`
    unless match = raw_version.scan(/\d+\.\d+\.\d+/).first
        raise "Failed to extract git version from `git --version` (#{raw_version.inspect})"
    end
    Gem::Version.new(match)
end

.optionsObject



15
16
17
18
19
# File 'lib/pod-pipeline/command.rb', line 15

def self.options
    [
      ['--help', '展示改命令的介绍面板'],
    ]
end

.options_extensionObject



21
22
23
24
25
26
27
28
29
# File 'lib/pod-pipeline/command.rb', line 21

def self.options_extension
    options = Array.new
    options_extension_hash.each { |_key, _options_extension|
        _options_extension.each { |_option_extension| 
          options << [_option_extension.first.gsub(/(--)(.*)/,"\\1#{_key}-\\2"), _option_extension.last]
        } 
    }
    options
end

.options_extension_hashObject



31
32
33
34
35
# File 'lib/pod-pipeline/command.rb', line 31

def self.options_extension_hash
    Hash[
      
    ]
end

.run(argv) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/pod-pipeline/command.rb', line 37

def self.run(argv)
    ensure_not_root_or_allowed! argv
    verify_minimum_git_version!
    verify_xcode_license_approved!
      
    super(argv)
end

.verify_minimum_git_version!void

This method returns an undefined value.

检查Git版本号是否低于 1.8.5

Raises:

  • Git版本号低于 1.8.5



73
74
75
76
77
# File 'lib/pod-pipeline/command.rb', line 73

def self.verify_minimum_git_version!
    if git_version < Gem::Version.new('1.8.5')
        raise 'You need at least git version 1.8.5 to use Pod-Pipeline'
    end
end

.verify_xcode_license_approved!void

This method returns an undefined value.

检查xcode许可是否被批准



84
85
86
87
88
89
90
# File 'lib/pod-pipeline/command.rb', line 84

def self.verify_xcode_license_approved!
    if `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$?.success?
      raise 'You have not agreed to the Xcode license, which ' \
        'you must do to use CocoaPods. Agree to the license by running: ' \
        '`xcodebuild -license`.'
    end
end

Instance Method Details

#argv_extensionObject



116
117
118
# File 'lib/pod-pipeline/command.rb', line 116

def argv_extension
    @argv_extension 
end