Class: Dockerun::Command::Init
- Inherits:
-
Object
- Object
- Dockerun::Command::Init
show all
- Includes:
- TR::CondUtils, TTY::Option
- Defined in:
- lib/dockerun/command/init.rb
Defined Under Namespace
Classes: MultipleTemplateDetected
Instance Method Summary
collapse
Instance Method Details
#init_dockerfile(&block) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/dockerun/command/init.rb', line 36
def init_dockerfile(&block)
loc = "."
loc = params[:location] if not_empty?(params[:location])
loc = File.expand_path(loc)
out = nil
if File.directory?(loc)
out = File.join(loc, "Dockerfile.dockerun")
else
out = File.join(File.dirname(loc), "Dockerfile.dockerun")
end
avail = ::Dockerun::Template::TemplateEngine.available_templates
selTemp = nil
if avail.length > 1
if block
selTemp = block.call(:multiple_templates_detected, avail)
else
raise MultipleTemplateDetected, "Multiple template is available but no selected is given."
end
else
selTemp = avail.first
end
tw = ::Dockerun::Template::TemplateWriter.new(selTemp)
userFields = tw.user_configurables
if block
tw.user_configurables = block.call(:prompt_user_configurables, { template: selTemp, userFields: userFields })
end
res = tw.compile
File.open(out, "w") do |f|
f.write res
end
out
end
|
#run(&block) ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/dockerun/command/init.rb', line 26
def run(&block)
if params[:help]
print help
exit
else
init_dockerfile(&block)
end
end
|