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.



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

def initialize(argv)
  @name = argv.shift_argument || ''

  @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
# 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

#replacementsObject



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

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

#runObject



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/vcpkg_pipeline/command/new.rb', line 46

def run
  VPL.error('未输入port名称') if @name.empty?

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

  Dir.replace_all(@name, replacements)

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