Class: VPL::Command::New

Inherits:
VPL::Command show all
Defined in:
lib/vcpkg_pipeline/command/new.rb

Overview

VPL::Command::New

Instance Attribute Summary

Attributes inherited from VPL::Command

#argv_extension

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from VPL::Command

ensure_not_root_or_allowed!, git_version, options_extension, options_extension_hash, run, verify_minimum_git_version!, verify_xcode_license_approved!

Constructor Details

#initialize(argv) ⇒ New

Returns a new instance of New.



31
32
33
34
35
36
37
38
# File 'lib/vcpkg_pipeline/command/new.rb', line 31

def initialize(argv)
  @name = argv.shift_argument
  VPL.error('未输入port名称') if @name.empty?

  @template = argv.option('template-url', '').split(',').first
  @template ||= 'https://github.com/TKCMake/vcport-template.git'
  super
end

Class Method Details

.optionsObject



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

def self.options
  [
    '--template-url=https://github.com/TKCMake/vcport-template.git',
    'vcport模版地址'
  ].concat(super).concat(options_extension)
end

Instance Method Details

#runObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/vcpkg_pipeline/command/new.rb', line 40

def run
  Git.clone(@template, @name, depth: 1)

  replacements = {
    'PT_PORT_NAME' => @name,
    'PT_USER_NAME' => Git.global_config('user.name')
  }
  Dir.replace_all(@name, replacements)

  git = Git.open(@name)
  git.remote.remove
  git.add('.')
  git.commit("init #{@name}", amend: true)
end