From 3bcaab101b11d48249190965534f38e8d26ee53e Mon Sep 17 00:00:00 2001 From: Fabian Schlenz Date: Mon, 25 Sep 2017 09:28:58 +0200 Subject: [PATCH] Added --list to list all known container names. --- dup.rb | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/dup.rb b/dup.rb index b679e0f..25412f6 100755 --- a/dup.rb +++ b/dup.rb @@ -163,6 +163,31 @@ def action_run(container, file) 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 container = nil $dry_run = false @@ -175,7 +200,8 @@ opts = GetoptLong.new( [ '--create', '-c', GetoptLong::NO_ARGUMENT ], [ '--help', '-h', 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| @@ -190,6 +216,9 @@ opts.each do |opt, arg| when '--dry-run' puts "Dry-run. Not going to execute any command." $dry_run = true + when '--list' + action = :list + needs_container = false when '--pull' $pull = true end @@ -215,7 +244,9 @@ file = "%s/%s.yml" % [ base_dir, container ] if action == :create action_create(container, file) elsif action == :run - action_run(container, file) + action_run(container, file) +elsif action == :list + action_list(base_dir) end