16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/milk_tea/bindings/cli.rb', line 16
def start
module_name = @argv.shift
= @argv.shift
unless module_name &&
@err.puts("missing module name or header path")
print_help
return 1
end
require_relative "../bindings"
options = parse_options
return 1 unless options
output_path = options.delete(:output_path)
nullable_report_path = options.delete(:nullable_report_path)
if nullable_report_path
require "json"
result = Bindgen.generate_with_report(module_name:, header_path:, **options)
source = result.fetch(:source)
report_path = File.expand_path(nullable_report_path)
FileUtils.mkdir_p(File.dirname(report_path))
File.write(report_path, JSON.pretty_generate(result.fetch(:nullable_policy_report)))
else
source = Bindgen.generate(module_name:, header_path:, **options)
end
if output_path
FileUtils.mkdir_p(File.dirname(File.expand_path(output_path)))
File.write(output_path, source)
@out.puts("generated #{} -> #{output_path}")
@out.puts("nullable report #{} -> #{report_path}") if nullable_report_path
else
@out.write(source)
@err.puts("wrote nullable report #{report_path}") if nullable_report_path
end
0
end
|