23
24
25
26
27
28
29
30
31
32
33
34
35
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/dockerun/command/stop_container.rb', line 23
def run(&block)
if params[:help]
print help
exit(0)
else
config = ::Dockerun::Config.from_storage
res = []
opts = []
config.image_names.each do |im|
config.container_names(im).each do |cn|
if is_container_exist?(cn)
if is_container_running?(cn)
res << "#{im} : #{cn} (Running)"
opts << cn
else
res << "#{im} : #{cn} (Not Running)"
end
else
res << "#{im} : #{cn} (Not Exist)"
end
end
end
if not opts.empty?
cli.puts "\n Running status of container(s) : ".yellow
res.sort.each do |r|
cli.puts " * #{r}".yellow
end
cli.puts
selConts = cli.multi_select("Please select which container to stop : ") do |m|
opts.each do |o|
m.choice o,o
end
m.choice "Abort", :quit
end
if selConts.include?(:quit)
cli.puts " * Abort was one of the selected option. Command aborted.".red
else
selConts.each do |sc|
begin
stop_container(sc)
cli.puts " Container '#{sc}' stopped successfully.".green
rescue DockerContainerStopFailed => ex
cli.puts " Container '#{sc}' failed to be stopped".red
end
end
end
else
cli.say " * There is no container found to be running * ".yellow
end
cli.puts "\n Stop container command completed successfully \n\n".yellow
end
end
|