Class: MGit::Forall
Overview
eg: mgit forall -c ‘git status’
Constant Summary
collapse
- OPT_LIST =
{
:command => '--command',
:command_s => '-c',
:concurrent => '--concurrent',
:concurrent_s => '-n',
}.freeze
Constants inherited
from BaseCommand
BaseCommand::HIGH_PRIORITY_OPT_LIST, BaseCommand::SELECTABLE_OPT_LIST
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from BaseCommand
#all_repos, cmd, #exec_light_repos, #generate_config_repo, inherited, #initialize, #locked_repos, #run
Class Method Details
.description ⇒ Object
71
72
73
|
# File 'lib/m-git/command/forall.rb', line 71
def self.description
"对多仓库批量执行指令。"
end
|
.usage ⇒ Object
75
76
77
|
# File 'lib/m-git/command/forall.rb', line 75
def self.usage
"mgit forall -c '<instruction>' [(-m|-e) <repo>...] [-n] [-h]"
end
|
Instance Method Details
#enable_repo_selection ⇒ Object
63
64
65
|
# File 'lib/m-git/command/forall.rb', line 63
def enable_repo_selection
true
end
|
#enable_short_basic_option ⇒ Object
67
68
69
|
# File 'lib/m-git/command/forall.rb', line 67
def enable_short_basic_option
true
end
|
#execute(argv) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/m-git/command/forall.rb', line 36
def execute(argv)
Workspace.check_branch_consistency
Output.puts_start_cmd
for_all_cmd = argv.opt(OPT_LIST[:command]).value
use_concurrent = !argv.opt(OPT_LIST[:concurrent]).nil?
if use_concurrent
succeed_repos, error_repos = Workspace.execute_common_cmd_with_repos_concurrent(for_all_cmd, all_repos)
else
succeed_repos, error_repos = Workspace.execute_common_cmd_with_repos(for_all_cmd, all_repos)
end
no_output_repos = []
succeed_repos.each { |repo_name, output|
if output.length > 0
puts Output.generate_title_block(repo_name) { output } + "\n"
else
no_output_repos.push(repo_name)
end
}
Output.puts_remind_block(no_output_repos, "以上仓库无输出!") if no_output_repos.length > 0
Output.puts_succeed_cmd(argv.absolute_cmd) if error_repos.length == 0
end
|
#options ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/m-git/command/forall.rb', line 18
def options
return [
ARGV::Opt.new(OPT_LIST[:command],
short_key:OPT_LIST[:command_s],
info:'必须参数,指定需要执行的shell命令,如:"mgit forall -c \'git status -s\'"(注意要带引号)。',
type: :string),
ARGV::Opt.new(OPT_LIST[:concurrent],
short_key:OPT_LIST[:concurrent_s],
info:'可选参数,若指定,则shell命令以多线程方式执行。',
type: :boolean)
].concat(super)
end
|
#validate(argv) ⇒ Object
31
32
33
34
|
# File 'lib/m-git/command/forall.rb', line 31
def validate(argv)
Foundation.help!("输入非法参数:#{argv.git_opts}。请通过\"mgit #{argv.cmd} --help\"查看用法。") if argv.git_opts.length > 0
Foundation.help!("请输入必须参数--command,示例:mgit forall -c 'git status'") if argv.opt(OPT_LIST[:command]).nil?
end
|