Reduced the verbosity and in turn added -v/--verbose to reactivate the verbosity.
This commit is contained in:
parent
2377131483
commit
61b3f2b98a
26
dup.rb
26
dup.rb
@ -115,11 +115,11 @@ def action_help
|
|||||||
puts "-l, --list Lists all available containers."
|
puts "-l, --list Lists all available containers."
|
||||||
puts " --host Starts a container with net: host - which implies not using ports, networks and/or links."
|
puts " --host Starts a container with net: host - which implies not using ports, networks and/or links."
|
||||||
puts " --regenerate Generates YAML content from a running container."
|
puts " --regenerate Generates YAML content from a running container."
|
||||||
|
puts "-v, --verbose More verbose output."
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def run_cmd(cmd, ignore_returnvalue=false, catch_interrupt=false)
|
verbose "+ #{cmd}"
|
||||||
puts "+ #{cmd}" if $dry_run
|
|
||||||
returnvalue=false
|
returnvalue=false
|
||||||
begin
|
begin
|
||||||
returnvalue = $dry_run ? true : system("bash -c #{cmd.shellescape}")
|
returnvalue = $dry_run ? true : system("bash -c #{cmd.shellescape}")
|
||||||
@ -281,7 +281,7 @@ class Container
|
|||||||
end
|
end
|
||||||
|
|
||||||
def stop_and_remove
|
def stop_and_remove
|
||||||
puts "Stopping and removing old container..."
|
verbose "Stopping and removing old container..."
|
||||||
run_cmd("docker rm -f #{@name.shellescape} >/dev/null 2>&1", true)
|
run_cmd("docker rm -f #{@name.shellescape} >/dev/null 2>&1", true)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -290,9 +290,9 @@ class Container
|
|||||||
networks = `docker network ls --format '{{.Name}}'`.split
|
networks = `docker network ls --format '{{.Name}}'`.split
|
||||||
@data["networks"].each do |network|
|
@data["networks"].each do |network|
|
||||||
if networks.include?(network)
|
if networks.include?(network)
|
||||||
puts "Network #{network} exists."
|
verbose "Network #{network} exists."
|
||||||
else
|
else
|
||||||
puts "Creating network #{network}..."
|
verbose "Creating network #{network}..."
|
||||||
run_cmd("docker network create #{network.shellescape}", true)
|
run_cmd("docker network create #{network.shellescape}", true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -302,14 +302,14 @@ class Container
|
|||||||
def connect_to_networks
|
def connect_to_networks
|
||||||
if !$net_host && @data["networks"].count>0
|
if !$net_host && @data["networks"].count>0
|
||||||
@data["networks"].each do |network|
|
@data["networks"].each do |network|
|
||||||
puts "Connecting container to network #{network}..."
|
verbose "Connecting container to network #{network}..."
|
||||||
run_cmd("docker network connect #{network.shellescape} #{@name.shellescape} >/dev/null", true)
|
run_cmd("docker network connect #{network.shellescape} #{@name.shellescape} >/dev/null", true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def attach
|
def attach
|
||||||
puts "Attaching container..."
|
verbose "Attaching container..."
|
||||||
run_cmd("docker attach #{@name.shellescape}")
|
run_cmd("docker attach #{@name.shellescape}")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -336,13 +336,13 @@ class Container
|
|||||||
|
|
||||||
self.create_networks
|
self.create_networks
|
||||||
|
|
||||||
puts "Creating container..."
|
verbose "Creating container..."
|
||||||
cmd = build_run_command
|
cmd = build_run_command
|
||||||
run_cmd(cmd.compact.join(" ") + " >/dev/null")
|
run_cmd(cmd.compact.join(" ") + " >/dev/null")
|
||||||
|
|
||||||
self.connect_to_networks
|
self.connect_to_networks
|
||||||
|
|
||||||
puts "Starting container..."
|
verbose "Starting container..."
|
||||||
run_cmd("docker start #{@name.shellescape} >/dev/null")
|
run_cmd("docker start #{@name.shellescape} >/dev/null")
|
||||||
|
|
||||||
(@data["after_run"] || []).each{|cmd| run_cmd(cmd)}
|
(@data["after_run"] || []).each{|cmd| run_cmd(cmd)}
|
||||||
@ -379,9 +379,12 @@ class Container
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def verbose(str); puts(str) if $verbose; end
|
||||||
|
|
||||||
action = :run
|
action = :run
|
||||||
container = nil
|
container = nil
|
||||||
$dry_run = false
|
$dry_run = false
|
||||||
|
$verbose = false
|
||||||
$pull = false
|
$pull = false
|
||||||
needs_container = true
|
needs_container = true
|
||||||
completion_str = ""
|
completion_str = ""
|
||||||
@ -405,7 +408,8 @@ opts = GetoptLong.new(
|
|||||||
[ '--update', '-u', GetoptLong::NO_ARGUMENT ],
|
[ '--update', '-u', GetoptLong::NO_ARGUMENT ],
|
||||||
[ '--_completion', GetoptLong::OPTIONAL_ARGUMENT ],
|
[ '--_completion', GetoptLong::OPTIONAL_ARGUMENT ],
|
||||||
[ '--host', GetoptLong::NO_ARGUMENT ],
|
[ '--host', GetoptLong::NO_ARGUMENT ],
|
||||||
[ '--regenerate', GetoptLong::NO_ARGUMENT ]
|
[ '--verbose', '-v', GetoptLong::NO_ARGUMENT ],
|
||||||
|
[ '--all', GetoptLong::NO_ARGUMENT ],
|
||||||
)
|
)
|
||||||
|
|
||||||
opts.each do |opt, arg|
|
opts.each do |opt, arg|
|
||||||
@ -436,6 +440,8 @@ opts.each do |opt, arg|
|
|||||||
$net_host = true
|
$net_host = true
|
||||||
when '--regenerate'
|
when '--regenerate'
|
||||||
action = :regenerate
|
action = :regenerate
|
||||||
|
when '--verbose'
|
||||||
|
$verbose = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user