Class: MGit::Self
Overview
该指令用于不带指令的输入:mgit –help,用于执行mgit的一级参数(如“mgit –help”的“–help”)
Constant Summary
collapse
- HELP_INTRODUCTION =
<<INTRO
#{Output.info_title("Description:")}
mgit是多仓库管理工具,通过将git指令作用到多个仓库,实现批量的版本管理功能
更多介绍:https://github.com/baidu/mgit
INTRO
- OPT_LIST =
{
:all => '--all',
:all_s => '-a',
:list => '--list',
:list_s => '-l',
:size => '--size',
:size_s => '-s',
:version => '--version',
:version_s => '-v',
:workspace => '--workspace',
:workspace_s => '-w'
}.freeze
Constants inherited
from BaseCommand
BaseCommand::HIGH_PRIORITY_OPT_LIST, BaseCommand::SELECTABLE_OPT_LIST
Instance Method Summary
collapse
Methods inherited from BaseCommand
#all_repos, cmd, #exec_light_repos, #generate_config_repo, inherited, #initialize, #locked_repos, #run
Instance Method Details
#enable_short_basic_option ⇒ Object
217
218
219
|
# File 'lib/m-git/command/self.rb', line 217
def enable_short_basic_option
return true
end
|
#execute(argv) ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/m-git/command/self.rb', line 62
def execute(argv)
= argv.git_opts
if .length > 0
Output.puts_fail_message("输入无效参数:#{}\n")
show_help(argv)
exit
end
argv.enumerate_valid_opts { |opt|
if opt.key == OPT_LIST[:list] || opt.key == OPT_LIST[:list_s]
show_all_repos(argv)
return
elsif opt.key == OPT_LIST[:size] || opt.key == OPT_LIST[:size_s]
show_repo_size
return
elsif opt.key == OPT_LIST[:version] || opt.key == OPT_LIST[:version_s]
show_version
return
elsif opt.key == OPT_LIST[:workspace] || opt.key == OPT_LIST[:workspace_s]
show_workspace
return
end
}
show_help(argv)
end
|
#options ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/m-git/command/self.rb', line 31
def options
return [
ARGV::Opt.new(OPT_LIST[:list], short_key:OPT_LIST[:list_s], info:"显示MGit管理的仓库。", type: :boolean),
ARGV::Opt.new(OPT_LIST[:size], short_key:OPT_LIST[:size_s], info:"显示MGit管理的仓库的磁盘占用量。", type: :boolean),
ARGV::Opt.new(OPT_LIST[:all], short_key:OPT_LIST[:all_s], info:"指定操作所有定义在manifest内的仓库,可配合-l合并使用: \"mgit -al\"。", type: :boolean),
ARGV::Opt.new(OPT_LIST[:version], short_key:OPT_LIST[:version_s], info:"显示当前MGit版本。", type: :boolean),
ARGV::Opt.new(OPT_LIST[:workspace], short_key:OPT_LIST[:workspace_s], info:"显示当前MGit工程管理根目录(.mgit所在目录)。", type: :boolean)
].concat(super)
end
|
#post_exec ⇒ Object
54
55
|
# File 'lib/m-git/command/self.rb', line 54
def post_exec
end
|
#pre_exec ⇒ Object
51
52
|
# File 'lib/m-git/command/self.rb', line 51
def pre_exec
end
|
#prepare_repos(with_excluded: false) ⇒ Object
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
# File 'lib/m-git/command/self.rb', line 188
def prepare_repos(with_excluded:false)
existing_repos = []
missing_repos = []
Workspace.config.light_repos.each { |light_repo|
if with_excluded || !light_repo.mgit_excluded
repo_exist = Repo.is_git_repo?(light_repo.abs_dest(Workspace.root))
if repo_exist
existing_repos.push(light_repo)
else
missing_repos.push(light_repo)
end
end
}
return existing_repos, missing_repos
end
|
#show_all_repos(argv) ⇒ Object
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/m-git/command/self.rb', line 130
def show_all_repos(argv)
prepare
list_all = argv.opt_list.did_set_opt?(OPT_LIST[:all])
existing_repos, missing_repos = prepare_repos(with_excluded:list_all)
list = {}
if existing_repos.length > 0
existing_repos.sort_by { |e| e.name }.each { |light_repo|
dir = File.join("<ROOT>", File.dirname(light_repo.path)).bold
list[dir] = [] if list[dir].nil?
list[dir].push(light_repo.name)
}
end
if missing_repos.length > 0
list['本地缺失'.bold] = missing_repos.sort_by { |e| e.name }.map { |e| e.name }
end
list_array = []
list.each { |dir, list|
list_array.push([dir.bold, list])
}
puts Output.generate_table_combination(list_array, separator:'|')
if list_all
message = "共统计#{existing_repos.length + missing_repos.length}个仓库。"
else
message = "mgit目前共管理#{existing_repos.length + missing_repos.length}个仓库。"
end
Output.puts_remind_message(message)
Output.puts_fail_message("有#{missing_repos.length}个仓库本地缺失!") if missing_repos.length > 0
end
|
#show_help(argv) ⇒ Object
91
92
93
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
120
121
122
123
124
125
126
127
128
|
# File 'lib/m-git/command/self.rb', line 91
def show_help(argv)
head_space = ' '
middle_space = ' '
output = HELP_INTRODUCTION output += "#{Output.info_title("Usage:")}\n\n#{head_space}$ #{Output.green_message("mgit <mgit_options>")}\n"
output += "#{head_space}$ #{Output.green_message("mgit <command> [<command_option>...] [<value>...]")}\n\n"
output += "#{Output.info_title("MGit Option:")}\n\n"
divider = ", "
longest_opt = argv.opt_list.opts.max_by { |e| "#{Output.blue_message("#{e.key}#{divider + e.short_key if !e.short_key.nil?}")}".length }
max_opt_length = "#{longest_opt.short_key + divider + longest_opt.key}".length
mgit_option_info = ''
argv.opt_list.opts.each { |opt|
key = "#{opt.short_key + divider + opt.key}"
mgit_option_info += "#{head_space}#{Output.blue_message(key)}#{' ' * (max_opt_length - key.length + middle_space.length)}#{argv.info(opt.key)}\n"
}
output += mgit_option_info + "\n"
output += "#{Output.info_title("Command:")}\n\n"
= '+ '
cmd_info = ''
max_cmd_length = Output.blue_message( + CommandManager.commands.keys.max_by { |e| e.length }.to_s).length
CommandManager.commands.keys.sort.each { |cmd_name|
next if cmd_name == self.class.cmd
cls_name = CommandManager.commands[cmd_name]
cmd_name = Output.green_message( + cmd_name.downcase.to_s)
cmd_info += "#{head_space}#{cmd_name}#{' ' * (max_cmd_length - cmd_name.length + middle_space.length)}#{cls_name.description}\n"
}
output += cmd_info + "\n"
output += "#{Output.info_title("Command Option:")}\n\n#{head_space}请通过[ mgit <command> --help ]查看。\n\n"
output += "#{Output.info_title("Version:")}\n\n#{head_space}#{MGit::VERSION}\n"
puts output
end
|
#show_version ⇒ Object
213
214
215
|
# File 'lib/m-git/command/self.rb', line 213
def show_version
puts MGit::VERSION
end
|
#usage(argv) ⇒ Object
57
58
59
|
# File 'lib/m-git/command/self.rb', line 57
def usage(argv)
show_help(argv)
end
|
#validate(argv) ⇒ Object
41
42
43
|
# File 'lib/m-git/command/self.rb', line 41
def validate(argv)
Foundation.help!("输入非法参数:#{argv.git_opts}。请通过\"mgit --help\"查看用法。") if argv.git_opts.length > 0
end
|