Reduced the verbosity and in turn added -v/--verbose to reactivate the verbosity.

This commit is contained in:
Fabian Schlenz 2020-09-04 06:11:48 +02:00
parent 2377131483
commit 61b3f2b98a
1 changed files with 16 additions and 10 deletions

26
dup.rb
View File

@ -115,11 +115,11 @@ def action_help
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 " --regenerate Generates YAML content from a running container."
puts "-v, --verbose More verbose output."
exit 1
end
def run_cmd(cmd, ignore_returnvalue=false, catch_interrupt=false)
puts "+ #{cmd}" if $dry_run
verbose "+ #{cmd}"
returnvalue=false
begin
returnvalue = $dry_run ? true : system("bash -c #{cmd.shellescape}")
@ -281,7 +281,7 @@ class Container
end
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)
end
@ -290,9 +290,9 @@ class Container
networks = `docker network ls --format '{{.Name}}'`.split
@data["networks"].each do |network|
if networks.include?(network)
puts "Network #{network} exists."
verbose "Network #{network} exists."
else
puts "Creating network #{network}..."
verbose "Creating network #{network}..."
run_cmd("docker network create #{network.shellescape}", true)
end
end
@ -302,14 +302,14 @@ class Container
def connect_to_networks
if !$net_host && @data["networks"].count>0
@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)
end
end
end
def attach
puts "Attaching container..."
verbose "Attaching container..."
run_cmd("docker attach #{@name.shellescape}")
end
@ -336,13 +336,13 @@ class Container
self.create_networks
puts "Creating container..."
verbose "Creating container..."
cmd = build_run_command
run_cmd(cmd.compact.join(" ") + " >/dev/null")
self.connect_to_networks
puts "Starting container..."
verbose "Starting container..."
run_cmd("docker start #{@name.shellescape} >/dev/null")
(@data["after_run"] || []).each{|cmd| run_cmd(cmd)}
@ -379,9 +379,12 @@ class Container
end
end
def verbose(str); puts(str) if $verbose; end
action = :run
container = nil
$dry_run = false
$verbose = false
$pull = false
needs_container = true
completion_str = ""
@ -405,7 +408,8 @@ opts = GetoptLong.new(
[ '--update', '-u', GetoptLong::NO_ARGUMENT ],
[ '--_completion', GetoptLong::OPTIONAL_ARGUMENT ],
[ '--host', GetoptLong::NO_ARGUMENT ],
[ '--regenerate', GetoptLong::NO_ARGUMENT ]
[ '--verbose', '-v', GetoptLong::NO_ARGUMENT ],
[ '--all', GetoptLong::NO_ARGUMENT ],
)
opts.each do |opt, arg|
@ -436,6 +440,8 @@ opts.each do |opt, arg|
$net_host = true
when '--regenerate'
action = :regenerate
when '--verbose'
$verbose = true
end
end