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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'lib/kwatable/main.rb', line 36
def execute()
options, properties, filenames = _parse_options(@argv)
if options[?h] || options[?v]
puts _version() if options[?v]
return unless options[?h]
puts _template_info(options) if options[?t]
puts _usage() if !options[?t]
puts _available_template(options) if !options[?t]
return
end
if dir = options[?d]
_option_error(:dir_notfound, dir) unless test(?e, dir)
_option_error(:dir_notadir, dir) unless test(?d, dir)
end
tabledefs = []
check_only = options[?c]
s = '' if check_only
filenames.each do |filename|
tabledef, content = _load_yaml(filename, options[?T])
tabledefs << tabledef
unless options[?u]
errors = Kwatable.validate(tabledef, content)
if !errors || errors.empty?
s << "#{filename}: valid.\n" if check_only
else
s << "#{filename}: INVALID!\n" if check_only
s2 = errors.sort.collect { |err|
"%s:%d: %s: %s" % [filename, err.linenum, err.path, err.message]
}.join("\n")
if check_only
s << s2 << "\n"
else
_option_error(:tabledef_validation_error, s2)
end
end
end
end
return s if check_only
tabledef = tabledefs.shift
tabledefs.each do |tdef|
tabledef = _merge_tabledefs(tabledef, tdef)
end
manipulator = Manipulator.new()
manipulator.manipulate(tabledef)
$stderr.puts tabledef.to_yaml if options[?D]
filename = options[?t]
unless filename
return nil if options[?D]
_option_error(:template_notspecified)
end
template_pathlist = _template_pathlist(options[?I])
template_filename = _find_template(filename, template_pathlist)
hash = { :options=>options, :properties=>properties,
:template_filename=>template_filename,
:template_pathlist=>template_pathlist,
}
hash[:tables] = tabledef['tables']
context = _create_context(hash)
output = Util.eval_template(template_filename, context)
output_files = context.instance_variable_get("@output_files")
if output_files
output_files.each do |filename, content, message_key|
_write_file(filename, content, message_key, options)
end
output = nil
end
return output
end
|