Added --list to list all known container names.

This commit is contained in:
Fabian Schlenz 2017-09-25 09:28:58 +02:00
parent 648da782d4
commit 3bcaab101b

33
dup.rb
View File

@ -163,6 +163,31 @@ def action_run(container, file)
end end
end end
def action_list(base_dir)
errors = []
Dir[File.join(base_dir, "*.yml")].sort.each do |file|
basename = File.basename(file)[0..-5]
yaml = File.open(file, "r") {|f| YAML.load(f.read)}
keys = yaml.keys
if keys.include? basename
puts basename
keys.each {|k| puts " + #{k}" unless k==basename}
else
errors << "#{file}:\n Missing a key called #{basename}\n Has keys:\n#{keys.map{|k| " #{k}"}.join("\n")}"
end
end
if !errors.empty?
puts
puts "ERRORS:"
puts errors.join("\n\n")
exit 1
end
exit 0
end
action = :run action = :run
container = nil container = nil
$dry_run = false $dry_run = false
@ -175,7 +200,8 @@ opts = GetoptLong.new(
[ '--create', '-c', GetoptLong::NO_ARGUMENT ], [ '--create', '-c', GetoptLong::NO_ARGUMENT ],
[ '--help', '-h', GetoptLong::NO_ARGUMENT ], [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--dry-run', '-n', GetoptLong::NO_ARGUMENT ], [ '--dry-run', '-n', GetoptLong::NO_ARGUMENT ],
[ '--pull', '-p', GetoptLong::NO_ARGUMENT ] [ '--list', '-l', GetoptLong::NO_ARGUMENT ],
[ '--pull', '-p', GetoptLong::NO_ARGUMENT ],
) )
opts.each do |opt, arg| opts.each do |opt, arg|
@ -190,6 +216,9 @@ opts.each do |opt, arg|
when '--dry-run' when '--dry-run'
puts "Dry-run. Not going to execute any command." puts "Dry-run. Not going to execute any command."
$dry_run = true $dry_run = true
when '--list'
action = :list
needs_container = false
when '--pull' when '--pull'
$pull = true $pull = true
end end
@ -216,6 +245,8 @@ if action == :create
action_create(container, file) action_create(container, file)
elsif action == :run elsif action == :run
action_run(container, file) action_run(container, file)
elsif action == :list
action_list(base_dir)
end end