Class: VPL::Command

Inherits:
CLAide::Command
  • Object
show all
Defined in:
lib/vcpkg_pipeline/command.rb,
lib/vcpkg_pipeline/command/new.rb,
lib/vcpkg_pipeline/command/reg.rb,
lib/vcpkg_pipeline/command/scan.rb,
lib/vcpkg_pipeline/command/update.rb,
lib/vcpkg_pipeline/command/publish.rb,
lib/vcpkg_pipeline/command/reg/add.rb,
lib/vcpkg_pipeline/command/reg/list.rb,
lib/vcpkg_pipeline/command/scan/all.rb,
lib/vcpkg_pipeline/command/scan/name.rb,
lib/vcpkg_pipeline/command/reg/remove.rb,
lib/vcpkg_pipeline/command/update/all.rb,
lib/vcpkg_pipeline/command/update/git.rb,
lib/vcpkg_pipeline/command/scan/branch.rb,
lib/vcpkg_pipeline/command/scan/remote.rb,
lib/vcpkg_pipeline/command/update/spec.rb,
lib/vcpkg_pipeline/command/scan/version.rb,
lib/vcpkg_pipeline/command/update/cmake.rb,
lib/vcpkg_pipeline/command/update/vcport.rb

Overview

Command

Direct Known Subclasses

New, Publish, Reg, Scan, Update

Defined Under Namespace

Classes: New, Publish, Reg, Scan, Update

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Command

Returns a new instance of Command.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/vcpkg_pipeline/command.rb', line 94

def initialize(argv)
  @argv_extension = {}
  self.class.options_extension_hash.each_key do |key|
    @argv_extension[key] = []
    self.class.options.each do |option|
      name = option.first
      next unless name.include?(key)

      is_option = name.include? '='
      if is_option
        option = name.gsub(/(--)(.*)(=.*)/, '\\2')
        value = argv.option(option, '')
        unless value.empty?
          @argv_extension[key] << name.gsub(/(--.*=)(.*)/, "\\1#{value}").gsub("#{key}-",
                                                                               '')
        end
      else
        flag = name.gsub(/(--)(.*)/, '\\2')
        value = argv.flag?(flag)
        @argv_extension[key] << name.gsub("#{key}-", '') if value
      end
    end
  end

  super
end

Instance Attribute Details

#argv_extensionObject (readonly)

Returns the value of attribute argv_extension.



121
122
123
# File 'lib/vcpkg_pipeline/command.rb', line 121

def argv_extension
  @argv_extension
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用户



51
52
53
54
# File 'lib/vcpkg_pipeline/command.rb', line 51

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

.git_versionGem::Version

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

Returns:

  • (Gem::Version)


60
61
62
63
64
65
66
67
# File 'lib/vcpkg_pipeline/command.rb', line 60

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



18
19
20
21
22
# File 'lib/vcpkg_pipeline/command.rb', line 18

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

.options_extensionObject



24
25
26
27
28
29
30
31
32
# File 'lib/vcpkg_pipeline/command.rb', line 24

def self.options_extension
  options = []
  options_extension_hash.each do |key, options_extension|
    options_extension.each do |option_extension|
      options << [option_extension.first.gsub(/(--)(.*)/, "\\1#{key}-\\2"), option_extension.last]
    end
  end
  options
end

.options_extension_hashObject



34
35
36
# File 'lib/vcpkg_pipeline/command.rb', line 34

def self.options_extension_hash
  Hash[]
end

.run(argv) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/vcpkg_pipeline/command.rb', line 38

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



75
76
77
78
79
# File 'lib/vcpkg_pipeline/command.rb', line 75

def self.verify_minimum_git_version!
  return unless git_version < Gem::Version.new('1.8.5')

  raise 'You need at least git version 1.8.5 to use vcpkg-Pipeline'
end

.verify_xcode_license_approved!void

This method returns an undefined value.

检查xcode许可是否被批准



86
87
88
89
90
91
92
# File 'lib/vcpkg_pipeline/command.rb', line 86

def self.verify_xcode_license_approved!
  return unless `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$?.success?

  raise 'You have not agreed to the Xcode license, which ' \
      'you must do to use vcpkg. Agree to the license by running: ' \
      '`xcodebuild -license`'
end