Class: MGit::BaseCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/m-git/base_command.rb

Constant Summary collapse

HIGH_PRIORITY_OPT_LIST =
{
  :help         =>  '--help',
  :help_s       =>  '-h',
  :auto_exec    => '--auto-exec'
}.freeze
SELECTABLE_OPT_LIST =

注意使用时跟指令自身设置的参数对比,避免冲突

{
  :mrepo            =>  '--mrepo',
  :mrepo_s          =>  '-m',
  :exclude_mrepo    =>  '--el-mrepo',
  :exclude_mrepo_s  =>  '-e',
  :include_lock     =>  '--include-lock',
  :include_lock_s   =>  '-i',
  :continue         =>  '--continue',
  :abort            =>  '--abort',
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ BaseCommand

初始化

Parameters:



45
46
47
48
49
50
51
# File 'lib/m-git/base_command.rb', line 45

def initialize(argv)
  # 指令解析
  setup_argv(argv)
  process_highest_priority_option(argv)
  validate(argv)
  @argv = argv
end

Class Method Details

.cmdObject

当前命令行的命令比如checkout / status /..



14
15
16
# File 'lib/m-git/base_command.rb', line 14

def self.cmd
  name.split('::').last.downcase
end

.inherited(sub_klass) ⇒ Object



9
10
11
# File 'lib/m-git/base_command.rb', line 9

def self.inherited(sub_klass)
  CommandManager.register_command(sub_klass.cmd, sub_klass)
end

Instance Method Details

#all_repos(except_config: false) ⇒ Object


Workspace Bridge



67
68
69
# File 'lib/m-git/base_command.rb', line 67

def all_repos(except_config:false)
  Workspace.all_repos(except_config: except_config)
end

#exec_light_reposObject



75
76
77
# File 'lib/m-git/base_command.rb', line 75

def exec_light_repos
  Workspace.exec_light_repos
end

#generate_config_repoObject



79
80
81
# File 'lib/m-git/base_command.rb', line 79

def generate_config_repo
  Workspace.generate_config_repo
end

#locked_reposObject



71
72
73
# File 'lib/m-git/base_command.rb', line 71

def locked_repos
  Workspace.locked_repos
end

#runObject

— 禁止覆写 — 执行主方法



55
56
57
58
59
60
61
62
63
64
# File 'lib/m-git/base_command.rb', line 55

def run
  begin
    __config_repo_filter
    pre_exec
    execute(@argv)
    post_exec
  rescue SystemExit, Interrupt
    did_interrupt
  end
end