13
14
15
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/harmonized_tariff/cli.rb', line 13
def self.parse(args)
hts = HarmonizedTariff::Convert.new
opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: bundle exec bin/hts [options]"
opts.separator ""
opts.separator "Specific options:"
opts.on("-s", "--source [PATH]", "Set source file") do |source|
hts.source = source || hts.source
end
opts.on("-o", "--output [PATH]", "Set destination folder path") do |path|
@@destination = path || destination
end
opts.on("--type [TYPE]", "Select output format (json, xml, sql, gz (gzipped sql))") do |t|
@@type = t.downcase
end
opts.on("-v", "--verbose", "Print output to screen") do |d|
@@verbose = d
end
opts.separator ""
opts.separator "Common options:"
opts.on_tail("-h", "--help", "Show this message") do
puts opts
exit
end
opts.on_tail("--version", "Show version") do
puts HarmonizedTariff::VERSION
exit
end
end
opt_parser.parse!(args)
hts.load
if @@type == 'json'
self.output hts.toJSON
elsif @@type == 'xml'
self.output hts.toXML
elsif @@type == 'sql'
self.output hts.toSQL
elsif @@type == 'gz'
self.gzip hts.toSQL
end
end
|