Added --list to list all known container names.
This commit is contained in:
parent
648da782d4
commit
3bcaab101b
35
dup.rb
35
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
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user